diff --git a/clients/client-sts/src/defaultStsRoleAssumers.ts b/clients/client-sts/src/defaultStsRoleAssumers.ts index f68235ce8eac6..9daf5da2e9128 100644 --- a/clients/client-sts/src/defaultStsRoleAssumers.ts +++ b/clients/client-sts/src/defaultStsRoleAssumers.ts @@ -101,11 +101,13 @@ export const getDefaultRoleAssumer = ( stsOptions?.parentClientConfig?.region, credentialProviderLogger ); + const isCompatibleRequestHandler = !isH2(requestHandler); + stsClient = new stsClientCtor({ // A hack to make sts client uses the credential in current closure. credentialDefaultProvider: () => async () => closureSourceCreds, region: resolvedRegion, - requestHandler: requestHandler as any, + requestHandler: isCompatibleRequestHandler ? (requestHandler as any) : undefined, logger: logger as any, }); } @@ -157,9 +159,11 @@ export const getDefaultRoleAssumerWithWebIdentity = ( stsOptions?.parentClientConfig?.region, credentialProviderLogger ); + const isCompatibleRequestHandler = !isH2(requestHandler); + stsClient = new stsClientCtor({ region: resolvedRegion, - requestHandler: requestHandler as any, + requestHandler: isCompatibleRequestHandler ? (requestHandler as any) : undefined, logger: logger as any, }); } @@ -206,3 +210,7 @@ export const decorateDefaultCredentialProvider = ), ...input, }); + +const isH2 = (requestHandler: any): boolean => { + return requestHandler?.metadata?.handlerProtocol === "h2"; +}; diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts index 1f1d66f01dc39..f1183d03e993d 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts @@ -98,11 +98,13 @@ export const getDefaultRoleAssumer = ( stsOptions?.parentClientConfig?.region, credentialProviderLogger ); + const isCompatibleRequestHandler = !isH2(requestHandler); + stsClient = new stsClientCtor({ // A hack to make sts client uses the credential in current closure. credentialDefaultProvider: () => async () => closureSourceCreds, region: resolvedRegion, - requestHandler: requestHandler as any, + requestHandler: isCompatibleRequestHandler ? (requestHandler as any) : undefined, logger: logger as any, }); } @@ -154,9 +156,11 @@ export const getDefaultRoleAssumerWithWebIdentity = ( stsOptions?.parentClientConfig?.region, credentialProviderLogger ); + const isCompatibleRequestHandler = !isH2(requestHandler); + stsClient = new stsClientCtor({ region: resolvedRegion, - requestHandler: requestHandler as any, + requestHandler: isCompatibleRequestHandler ? (requestHandler as any) : undefined, logger: logger as any, }); } @@ -203,3 +207,7 @@ export const decorateDefaultCredentialProvider = ), ...input, }); + +const isH2 = (requestHandler: any): boolean => { + return requestHandler?.metadata?.handlerProtocol === "h2"; +};