@@ -23,6 +23,7 @@ A collection of all credential providers, with default clients.
23
23
1 . [ Supported Configuration] ( #supported-configuration )
24
24
1 . [ SSO login with AWS CLI] ( #sso-login-with-the-aws-cli )
25
25
1 . [ Sample Files] ( #sample-files-2 )
26
+ 1 . [ From Node.js default credentials provider chain] ( #fromNodeProviderChain )
26
27
27
28
## ` fromCognitoIdentity() `
28
29
@@ -119,7 +120,7 @@ const client = new FooClient({
119
120
// Optional. The master credentials used to get and refresh temporary credentials from AWS STS.
120
121
// If skipped, it uses the default credential resolved by internal STS client.
121
122
masterCredentials: fromTemporaryCredentials ({
122
- params: { RoleArn: " arn:aws:iam::1234567890:role/RoleA" }
123
+ params: { RoleArn: " arn:aws:iam::1234567890:role/RoleA" },
123
124
}),
124
125
// Required. Options passed to STS AssumeRole operation.
125
126
params: {
@@ -129,16 +130,16 @@ const client = new FooClient({
129
130
// session name with prefix of 'aws-sdk-js-'.
130
131
RoleSessionName: " aws-sdk-js-123" ,
131
132
// Optional. The duration, in seconds, of the role session.
132
- DurationSeconds: 3600
133
+ DurationSeconds: 3600 ,
133
134
// ... For more options see https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html
134
135
},
135
136
// Optional. Custom STS client configurations overriding the default ones.
136
137
clientConfig: { region },
137
138
// Optional. A function that returns a promise fulfilled with an MFA token code for the provided
138
139
// MFA Serial code. Required if `params` has `SerialNumber` config.
139
- mfaCodeProvider: async mfaSerial => {
140
- return " token"
141
- }
140
+ mfaCodeProvider: async ( mfaSerial ) => {
141
+ return " token" ;
142
+ },
142
143
}),
143
144
});
144
145
```
@@ -593,7 +594,7 @@ Successfully signed out of all SSO profiles.
593
594
### Sample files
594
595
595
596
This credential provider is only applicable if the profile specified in shared configuration and
596
- credentials files contain ALL of the following entries:
597
+ credentials files contain ALL of the following entries.
597
598
598
599
#### ` ~ / . aws/ credentials`
599
600
@@ -615,6 +616,40 @@ sso_role_name = SampleRole
615
616
sso_start_url = https: // d-abc123.awsapps.com/start
616
617
` ` `
617
618
619
+ ## ` fromNodeProviderChain ()`
620
+
621
+ The credential provider used as default in the Node.js clients, but with default role assumers so
622
+ you don't need to import them from STS client and supply them manually. You normally don't need
623
+ to use this explicitly in the client constructor. It is useful for utility functions requiring
624
+ credentials like S3 presigner, or RDS signer.
625
+
626
+ This credential provider will attempt to find credentials from the following sources (listed in
627
+ order of precedence):
628
+
629
+ - [Environment variables exposed via ` process .env ` ](#fromenv)
630
+ - [SSO credentials from token cache](#fromsso)
631
+ - [Web identity token credentials](#fromtokenfile)
632
+ - [Shared credentials and config ini files](#fromini)
633
+ - [The EC2/ECS Instance Metadata Service](#fromcontainermetadata-and-frominstancemetadata)
634
+
635
+ This credential provider will invoke one provider at a time and only
636
+ continue to the next if no credentials have been located. For example, if
637
+ the process finds values defined via the ` AWS_ACCESS_KEY_ID ` and
638
+ ` AWS_SECRET_ACCESS_KEY ` environment variables, the files at
639
+ ` ~ / . aws/ credentials` and ` ~ / . aws/ config` will not be read, nor will any
640
+ messages be sent to the Instance Metadata Service
641
+
642
+ ` ` ` js
643
+ import { fromNodeProviderChain } from " @aws-sdk/credential-providers" ; // ES6 import
644
+ // const { fromNodeProviderChain } = require("@aws-sdk/credential-providers") // CommonJS import
645
+ const credentialProvider = fromNodeProviderChain ({
646
+ // ...any input of fromEnv(), fromSSO(), fromTokenFile(), fromIni(),
647
+ // fromProcess(), fromInstanceMetadata(), fromContainerMetadata()
648
+ // Optional. Custom STS client configurations overriding the default ones.
649
+ clientConfig: { region },
650
+ });
651
+ ` ` `
652
+
618
653
[getcredentialsforidentity_api]: https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html
619
654
[getid_api]: https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetId.html
620
655
[assumerole_api]: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html
0 commit comments