1
- import { fromEnv } from "@aws-sdk/credential-provider-env" ;
1
+ import { ENV_KEY , ENV_SECRET , fromEnv } from "@aws-sdk/credential-provider-env" ;
2
2
import type { FromHttpOptions } from "@aws-sdk/credential-provider-http" ;
3
3
import type { FromIniInit } from "@aws-sdk/credential-provider-ini" ;
4
4
import type { FromProcessInit } from "@aws-sdk/credential-provider-process" ;
@@ -21,6 +21,11 @@ export type DefaultProviderInit = FromIniInit &
21
21
( FromSSOInit & Partial < SsoCredentialsParameters > ) &
22
22
FromTokenFileInit ;
23
23
24
+ /**
25
+ * @internal
26
+ */
27
+ let multipleCredentialSourceWarningEmitted = false ;
28
+
24
29
/**
25
30
* Creates a credential provider that will attempt to find credentials from the
26
31
* following sources (listed in order of precedence):
@@ -58,14 +63,36 @@ export type DefaultProviderInit = FromIniInit &
58
63
export const defaultProvider = ( init : DefaultProviderInit = { } ) : MemoizedProvider < AwsCredentialIdentity > =>
59
64
memoize (
60
65
chain (
61
- ...( init . profile || process . env [ ENV_PROFILE ]
62
- ? [ ]
63
- : [
64
- async ( ) => {
65
- init . logger ?. debug ( "@aws-sdk/credential-provider-node - defaultProvider::fromEnv" ) ;
66
- return fromEnv ( init ) ( ) ;
67
- } ,
68
- ] ) ,
66
+ async ( ) => {
67
+ const profile = init . profile ?? process . env [ ENV_PROFILE ] ;
68
+ if ( profile ) {
69
+ const envStaticCredentialsAreSet = process . env [ ENV_KEY ] && process . env [ ENV_SECRET ] ;
70
+ if ( envStaticCredentialsAreSet ) {
71
+ if ( ! multipleCredentialSourceWarningEmitted ) {
72
+ const warnFn =
73
+ init . logger ?. warn && init . logger ?. constructor ?. name !== "NoOpLogger" ? init . logger . warn : console . warn ;
74
+ warnFn (
75
+ `@aws-sdk/credential-provider-node - defaultProvider::fromEnv WARNING:
76
+ Multiple credential sources detected:
77
+ Both AWS_PROFILE and the pair AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY static credentials are set.
78
+ This SDK will proceed with the AWS_PROFILE value.
79
+
80
+ However, a future version may change this behavior to prefer the ENV static credentials.
81
+ Please ensure that your environment only sets either the AWS_PROFILE or the
82
+ AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY pair.
83
+ `
84
+ ) ;
85
+ multipleCredentialSourceWarningEmitted = true ;
86
+ }
87
+ throw new CredentialsProviderError ( "AWS_PROFILE is set, skipping fromEnv provider." , {
88
+ logger : init . logger ,
89
+ tryNextLink : true ,
90
+ } ) ;
91
+ }
92
+ }
93
+ init . logger ?. debug ( "@aws-sdk/credential-provider-node - defaultProvider::fromEnv" ) ;
94
+ return fromEnv ( init ) ( ) ;
95
+ } ,
69
96
async ( ) => {
70
97
init . logger ?. debug ( "@aws-sdk/credential-provider-node - defaultProvider::fromSSO" ) ;
71
98
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession } = init ;
0 commit comments