Skip to content

Commit

Permalink
fix(endpoints): resolve service-specific endpoint once per client
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Aug 29, 2024
1 parent e94028b commit d65bc40
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { loadConfig } from "@smithy/node-config-provider";

import { EndpointResolvedConfig } from "../resolveEndpointConfig";
import { getEndpointUrlConfig } from "./getEndpointUrlConfig";

export const getEndpointFromConfig = async (serviceId: string) => loadConfig(getEndpointUrlConfig(serviceId))();
/**
* @internal
*/
export const getEndpointFromConfig = async (config: Partial<EndpointResolvedConfig>) => {
if (config.serviceConfiguredEndpoint) {
return config.serviceConfiguredEndpoint;
}
return (config.serviceConfiguredEndpoint = await loadConfig(getEndpointUrlConfig(config.serviceId ?? ""))());
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export const getEndpointFromInstructions = async <
context?: HandlerExecutionContext
): Promise<EndpointV2> => {
if (!clientConfig.endpoint) {
const endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId || "");
const endpointFromConfig = await getEndpointFromConfig(clientConfig);

if (endpointFromConfig) {
clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig));
}
Expand Down
12 changes: 12 additions & 0 deletions packages/middleware-endpoint/src/resolveEndpointConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export interface EndpointInputConfig<T extends EndpointParameters = EndpointPara
* Enables FIPS compatible endpoints.
*/
useFipsEndpoint?: boolean | Provider<boolean>;

/**
* @internal
* This field is used internally so you should not fill any value to this field.
*/
serviceConfiguredEndpoint?: never;
}

interface PreviouslyResolved<T extends EndpointParameters = EndpointParameters> {
Expand Down Expand Up @@ -95,6 +101,12 @@ export interface EndpointResolvedConfig<T extends EndpointParameters = EndpointP
* @internal
*/
serviceId?: string;

/**
* A configured endpoint global or specific to the service from ENV or AWS SDK configuration files.
* @internal
*/
serviceConfiguredEndpoint?: string;
}

/**
Expand Down

0 comments on commit d65bc40

Please sign in to comment.