11import type { AssumeRoleCommandInput , STSClient , STSClientConfig } from "@aws-sdk/nested-clients/sts" ;
2- import type { CredentialProviderOptions } from "@aws-sdk/types" ;
2+ import type {
3+ AwsIdentityProperties ,
4+ CredentialProviderOptions ,
5+ RuntimeConfigAwsCredentialIdentityProvider ,
6+ } from "@aws-sdk/types" ;
37import { CredentialsProviderError } from "@smithy/property-provider" ;
48import { AwsCredentialIdentity , AwsCredentialIdentityProvider , Pluggable } from "@smithy/types" ;
59
@@ -53,9 +57,11 @@ export interface FromTemporaryCredentialsOptions extends CredentialProviderOptio
5357 *
5458 * @public
5559 */
56- export const fromTemporaryCredentials = ( options : FromTemporaryCredentialsOptions ) : AwsCredentialIdentityProvider => {
60+ export const fromTemporaryCredentials = (
61+ options : FromTemporaryCredentialsOptions
62+ ) : RuntimeConfigAwsCredentialIdentityProvider => {
5763 let stsClient : STSClient ;
58- return async ( ) : Promise < AwsCredentialIdentity > => {
64+ return async ( awsIdentityProperties : AwsIdentityProperties = { } ) : Promise < AwsCredentialIdentity > => {
5965 options . logger ?. debug ( "@aws-sdk/credential-providers - fromTemporaryCredentials (STS)" ) ;
6066 const params = { ...options . params , RoleSessionName : options . params . RoleSessionName ?? "aws-sdk-js-" + Date . now ( ) } ;
6167 if ( params ?. SerialNumber ) {
@@ -73,7 +79,26 @@ export const fromTemporaryCredentials = (options: FromTemporaryCredentialsOption
7379
7480 const { AssumeRoleCommand, STSClient } = await import ( "./loadSts" ) ;
7581
76- if ( ! stsClient ) stsClient = new STSClient ( { ...options . clientConfig , credentials : options . masterCredentials } ) ;
82+ if ( ! stsClient ) {
83+ const defaultCredentialsOrError = async ( ) => {
84+ if ( stsClient . config . runtime === "node" ) {
85+ const { fromNodeProviderChain } = await import ( "./fromNodeProviderChain" ) ;
86+ return fromNodeProviderChain ( { } ) ( ) ;
87+ }
88+ throw new CredentialsProviderError (
89+ "@aws-sdk/credential-providers::fromTemporaryCredentials - no default credentials found, masterCredentials needed to call fromTemporaryCredentials()." ,
90+ {
91+ logger : options . logger ,
92+ }
93+ ) ;
94+ } ;
95+ const { callerClientConfig } = awsIdentityProperties ;
96+ stsClient = new STSClient ( {
97+ ...options . clientConfig ,
98+ credentials :
99+ options . masterCredentials ?? callerClientConfig ?. credentialDefaultProvider ?.( ) ?? defaultCredentialsOrError ,
100+ } ) ;
101+ }
77102 if ( options . clientPlugins ) {
78103 for ( const plugin of options . clientPlugins ) {
79104 stsClient . middlewareStack . use ( plugin ) ;
0 commit comments