@@ -22,20 +22,11 @@ export type AwsCliV2CompatibleProviderOptions = Partial<AwsCredentialIdentity> &
22
22
FromSSOInit &
23
23
FromTokenFileInit & {
24
24
/**
25
- * Setting a client profile is similar to setting a value for the
26
- * AWS_PROFILE environment variable. Setting a profile on a client
27
- * in code only affects the single client instance, unlike AWS_PROFILE.
28
- *
29
- * When set, and only for environments where an AWS configuration
30
- * file exists, fields configurable by this file will be retrieved
31
- * from the specified profile within that file.
32
- * Conflicting code configuration and environment variables will
33
- * still have higher priority.
34
- *
35
- * For client credential resolution that involves checking the AWS
36
- * configuration file, the client's profile (this value) will be
37
- * used unless a different profile is set in the credential
38
- * provider options.
25
+ * The name of the profile to use while loading credentials.
26
+ * If specified, credentials will be loaded from the shared credentials file
27
+ * or shared config file using this profile.
28
+ * If not specified, the provider chain will attempt to load credentials from
29
+ * other sources according to order of precedence.
39
30
*
40
31
*/
41
32
profile ?: string ;
@@ -52,18 +43,18 @@ export type AwsCliV2CompatibleProviderOptions = Partial<AwsCredentialIdentity> &
52
43
* Creates a credential provider that sources credentials using the same priority
53
44
* chain as the AWS CLI v2:
54
45
*
55
- * 1. Static credentials from initialization
56
- * 2. Profile credentials (if profile specified)
57
- * 3. Environment variables
58
- * 4. Web Identity Token credentials
59
- * 5. SSO credentials
60
- * 6. Process credentials
61
- * 7. Remote credentials (ECS, EC2 Instance Metadata)
46
+ * 1. Static credentials from initialization.
47
+ * 2. Profile credentials (if profile specified).
48
+ * 3. Environment variables.
49
+ * 4. Web Identity Token credentials.
50
+ * 5. SSO credentials.
51
+ * 6. Process credentials.
52
+ * 7. Remote credentials (ECS, EC2 Instance Metadata).
62
53
*
63
54
* Uses dynamic imports and `createCredentialChain` to mimic AWS CLI V2 behavior.
64
55
*
65
56
* @param init - Configuration options for the provider chain
66
- * @returns An AWS credential provider function that returns a promise for credentials
57
+ * @returns An AWS credential provider function
67
58
*/
68
59
69
60
export const fromAwsCliV2CompatibleProviderChain =
@@ -73,31 +64,36 @@ export const fromAwsCliV2CompatibleProviderChain =
73
64
const init : AwsCliV2CompatibleProviderOptions = {
74
65
..._init ,
75
66
...callerClientConfig ,
67
+ profile : _init . profile ?? callerClientConfig ?. profile ,
76
68
logger : _init . logger ?? callerClientConfig ?. logger ,
77
69
} ;
78
70
79
71
init . logger ?. debug (
80
72
"@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - Initializing credential chain"
81
73
) ;
82
74
83
- const { profile, logger, ...awsCredentials } = init ;
75
+ const { profile, logger, accessKeyId , secretAccessKey , sessionToken , expiration , ...rest } = init ;
84
76
85
77
// 1. If credentials are explicitly provided, return them.
86
- if ( awsCredentials . accessKeyId && awsCredentials . secretAccessKey ) {
78
+ if ( accessKeyId && secretAccessKey ) {
87
79
logger ?. debug (
88
80
"@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - using static credentials from initialization"
89
81
) ;
90
- return awsCredentials as AwsCredentialIdentity ;
82
+ return {
83
+ accessKeyId,
84
+ secretAccessKey,
85
+ ...( sessionToken && { sessionToken } ) ,
86
+ ...( expiration && { expiration } ) ,
87
+ } as AwsCredentialIdentity ;
91
88
}
92
89
93
90
// 2. If a profile is explicitly passed, use `fromIni`.
94
91
if ( profile ) {
95
92
logger ?. debug (
96
- "@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - Using fromIni with profile:" ,
97
- profile
93
+ "@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - Using fromIni with profile:" + profile
98
94
) ;
99
95
const { fromIni } = await import ( "@aws-sdk/credential-provider-ini" ) ;
100
- return fromIni ( { profile, logger } ) ( ) ;
96
+ return fromIni ( { profile, logger, ... init } ) ( ) ;
101
97
}
102
98
103
99
logger ?. debug (
0 commit comments