From d65bc40a8411a22e0600fcf1b9209dd472043312 Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 29 Aug 2024 16:48:07 +0000 Subject: [PATCH] fix(endpoints): resolve service-specific endpoint once per client --- .../src/adaptors/getEndpointFromConfig.ts | 11 ++++++++++- .../src/adaptors/getEndpointFromInstructions.ts | 3 ++- .../middleware-endpoint/src/resolveEndpointConfig.ts | 12 ++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts index 903f66fbb21..7357a815a16 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts @@ -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) => { + if (config.serviceConfiguredEndpoint) { + return config.serviceConfiguredEndpoint; + } + return (config.serviceConfiguredEndpoint = await loadConfig(getEndpointUrlConfig(config.serviceId ?? ""))()); +}; diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts index 4e841c9a486..107a4a621a2 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts @@ -39,7 +39,8 @@ export const getEndpointFromInstructions = async < context?: HandlerExecutionContext ): Promise => { if (!clientConfig.endpoint) { - const endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId || ""); + const endpointFromConfig = await getEndpointFromConfig(clientConfig); + if (endpointFromConfig) { clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig)); } diff --git a/packages/middleware-endpoint/src/resolveEndpointConfig.ts b/packages/middleware-endpoint/src/resolveEndpointConfig.ts index 3bbd3368527..f4bc37ee022 100644 --- a/packages/middleware-endpoint/src/resolveEndpointConfig.ts +++ b/packages/middleware-endpoint/src/resolveEndpointConfig.ts @@ -42,6 +42,12 @@ export interface EndpointInputConfig; + + /** + * @internal + * This field is used internally so you should not fill any value to this field. + */ + serviceConfiguredEndpoint?: never; } interface PreviouslyResolved { @@ -95,6 +101,12 @@ export interface EndpointResolvedConfig