55
66A collection of all credential providers, with default clients.
77
8+ An ` AwsCredentialIdentityProvider ` is any function that matches the signature:
9+
10+ ``` ts
11+ () =>
12+ Promise <{
13+ /**
14+ * AWS access key ID
15+ */
16+ readonly accessKeyId: string ;
17+ /**
18+ * AWS secret access key
19+ */
20+ readonly secretAccessKey: string ;
21+ /**
22+ * A security or session token to use with these credentials. Usually
23+ * present for temporary credentials.
24+ */
25+ readonly sessionToken? : string ;
26+ /**
27+ * A `Date` when the identity or credential will no longer be accepted.
28+ * You can set or override this on the client side to force a refresh
29+ * call of the function supplying the credentials when 5 minutes remain.
30+ */
31+ readonly expiration? : Date ;
32+ }>;
33+ ```
34+
835# Table of Contents
936
10371 . [ From Cognito Identity] ( #fromcognitoidentity )
@@ -32,7 +59,7 @@ A collection of all credential providers, with default clients.
3259- Uses ` @aws-sdk/client-cognito-identity `
3360- Available in browsers & native apps
3461
35- The function ` fromCognitoIdentity() ` returns ` CredentialsProvider ` that retrieves credentials for
62+ The function ` fromCognitoIdentity() ` returns a credentials provider that retrieves credentials for
3663the provided identity ID. See [ GetCredentialsForIdentity API] [ getcredentialsforidentity_api ]
3764for more information.
3865
@@ -58,9 +85,10 @@ const client = new FooClient({
5885 " api.twitter.com" : " TWITTERTOKEN'" ,
5986 " www.digits.com" : " DIGITSTOKEN" ,
6087 },
61- // Optional. Custom client config if you need overwrite default Cognito Identity client
62- // configuration.
63- clientConfig: { region },
88+ // Optional overrides. This is passed to an inner Cognito client
89+ // instantiated to resolve the credentials. Region and profile
90+ // are inherited from the upper client if present unless overridden.
91+ clientConfig: {},
6492 }),
6593});
6694```
@@ -106,9 +134,10 @@ const client = new FooClient({
106134 " api.twitter.com" : " TWITTERTOKEN" ,
107135 " www.digits.com" : " DIGITSTOKEN" ,
108136 },
109- // Optional. Custom client config if you need overwrite default Cognito Identity client
110- // configuration.
111- clientConfig: { region },
137+ // Optional overrides. This is passed to an inner Cognito client
138+ // instantiated to resolve the credentials. Region and profile
139+ // are inherited from the upper client if present unless overridden.
140+ clientConfig: {},
112141 }),
113142});
114143```
@@ -144,13 +173,15 @@ const client = new FooClient({
144173 DurationSeconds: 3600 ,
145174 // ... For more options see https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html
146175 },
147- // Optional. Custom STS client configurations overriding the default ones.
148- clientConfig: { region },
149176 // Optional. A function that returns a promise fulfilled with an MFA token code for the provided
150177 // MFA Serial code. Required if `params` has `SerialNumber` config.
151178 mfaCodeProvider: async (mfaSerial ) => {
152179 return " token" ;
153180 },
181+ // Optional overrides. This is passed to an inner STS client instantiated to
182+ // resolve the credentials. Region and profile
183+ // are inherited from the upper client if present unless overridden.
184+ clientConfig: {},
154185 }),
155186});
156187```
@@ -172,24 +203,29 @@ const client = new FooClient({
172203 credentials: fromWebToken ({
173204 // Required. ARN of the role that the caller is assuming.
174205 roleArn: " arn:aws:iam::1234567890:role/RoleA" ,
175- // Required. The OAuth 2.0 access token or OpenID Connect ID token that is provided by the
176- // identity provider.
206+ // Required. The OAuth 2.0 access token or OpenID Connect ID token that is
207+ // provided by the identity provider.
177208 webIdentityToken: await openIdProvider (),
178- // Optional. Custom STS client configurations overriding the default ones.
179- clientConfig: { region },
180- // Optional. A function that assumes a role with web identity and returns a promise fulfilled
181- // with credentials for the assumed role.
209+ // Optional. A function that assumes a role with web identity and returns
210+ // a promise fulfilled with credentials for the assumed role.
182211 roleAssumerWithWebIdentity,
183212 // Optional. An identifier for the assumed role session.
184213 roleSessionName: " session_123" ,
185- // Optional. The fully qualified host component of the domain name of the identity provider.
214+ // Optional. The fully qualified host component of the domain name of the
215+ // identity provider.
186216 providerId: " graph.facebook.com" ,
187- // Optional. ARNs of the IAM managed policies that you want to use as managed session.
217+ // Optional. ARNs of the IAM managed policies that you want to use as
218+ // managed session.
188219 policyArns: [{ arn: " arn:aws:iam::1234567890:policy/SomePolicy" }],
189- // Optional. An IAM policy in JSON format that you want to use as an inline session policy.
220+ // Optional. An IAM policy in JSON format that you want to use as an
221+ // inline session policy.
190222 policy: " JSON_STRING" ,
191- // Optional. The duration, in seconds, of the role session. Default to 3600.
223+ // Optional. The duration, in seconds, of the role session. Default 3600.
192224 durationSeconds: 7200 ,
225+ // Optional overrides. This is passed to an inner STS client
226+ // instantiated to resolve the credentials. Region and profile
227+ // are inherited from the upper client if present unless overridden.
228+ clientConfig: {},
193229 }),
194230});
195231```
@@ -380,7 +416,7 @@ const client = new FooClient({
380416 on how the file is configured.
381417- Not available in browsers & native apps.
382418
383- ` fromIni ` creates ` AwsCredentialIdentityProvider ` functions that read from a shared credentials file at
419+ ` fromIni ` creates an ` AwsCredentialIdentityProvider ` function that reads from a shared credentials file at
384420` ~/.aws/credentials ` and a shared configuration file at ` ~/.aws/config ` . Both files are expected to
385421be INI formatted with section names corresponding to profiles. Sections in the credentials file are
386422treated as profile names, whereas profile sections in the config file must have the format of
@@ -395,10 +431,20 @@ import { fromIni } from "@aws-sdk/credential-providers"; // ES6 import
395431// const { fromIni } = require("@aws-sdk/credential-providers"); // CommonJS import
396432
397433const client = new FooClient ({
434+ // As of v3.714.0, an easy way to select a profile is to set it on the client.
435+ // This will read both client configuration and credentials instructions
436+ // from that profile. The order of priority is:
437+ // 1. this field (only applies to this client).
438+ // 2. AWS_PROFILE environment variable (affects all clients).
439+ // 3. the default profile.
440+ profile: " my-profile" ,
398441 credentials: fromIni ({
399- // Optional. The configuration profile to use. If not specified, the provider will use the value
400- // in the `AWS_PROFILE` environment variable or a default of `default`.
401- profile: " profile" ,
442+ // Optional. Defaults to the client's profile if that is set.
443+ // You can specify a profile here as well, but this applies
444+ // only to the credential resolution and not to the upper client.
445+ // Use this instead of the client profile if you need a separate profile
446+ // for credentials.
447+ profile: " my-profile" ,
402448 // Optional. The path to the shared credentials file. If not specified, the provider will use
403449 // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of
404450 // `~/.aws/credentials`.
@@ -412,8 +458,14 @@ const client = new FooClient({
412458 mfaCodeProvider: async (mfaSerial ) => {
413459 return " token" ;
414460 },
415- // Optional. Custom STS client configurations overriding the default ones.
416- clientConfig: { region },
461+ // Optional overrides. This is passed to an inner STS or SSO client
462+ // instantiated to resolve the credentials. Region and profile
463+ // are inherited from the upper client if present unless overridden, so
464+ // it should not be necessary to set those.
465+ //
466+ // Warning: setting a region here overrides the region set in the config file
467+ // for the selected profile.
468+ clientConfig: {},
417469 }),
418470});
419471```
@@ -540,10 +592,15 @@ import { fromProcess } from "@aws-sdk/credential-providers"; // ES6 import
540592// const { fromProcess } = require("@aws-sdk/credential-providers"); // CommonJS import
541593
542594const client = new FooClient ({
595+ // Optional, available on clients as of v3.714.0.
596+ profile: " my-profile" ,
543597 credentials: fromProcess ({
544- // Optional. The configuration profile to use. If not specified, the provider will use the value
545- // in the `AWS_PROFILE` environment variable or a default of `default`.
546- profile: " profile" ,
598+ // Optional. Defaults to the client's profile if that is set.
599+ // You can specify a profile here as well, but this applies
600+ // only to the credential resolution and not to the upper client.
601+ // Use this instead of the client profile if you need a separate profile
602+ // for credentials.
603+ profile: " my-profile" ,
547604 // Optional. The path to the shared credentials file. If not specified, the provider will use
548605 // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of
549606 // `~/.aws/credentials`.
@@ -617,9 +674,12 @@ import { fromTokenFile } from "@aws-sdk/credential-providers"; // ES6 import
617674// const { fromTokenFile } = require("@aws-sdk/credential-providers"); // CommonJS import
618675
619676const client = new FooClient ({
677+ region: " us-west-2" ,
620678 credentials: fromTokenFile ({
621- // Optional. STS client config to make the assume role request.
622- clientConfig: { region }
679+ // Optional overrides. This is passed to an inner STS client
680+ // instantiated to resolve the credentials. Region is inherited
681+ // from the upper client if present unless overridden.
682+ clientConfig: {}
623683 });
624684});
625685```
@@ -655,9 +715,14 @@ import { fromSSO } from "@aws-sdk/credential-providers"; // ES6 import
655715// const { fromSSO } = require("@aws-sdk/credential-providers") // CommonJS import
656716
657717const client = new FooClient ({
658- credentials: fromSSO ({
659- // Optional. The configuration profile to use. If not specified, the provider will use the value
660- // in the `AWS_PROFILE` environment variable or `default` by default.
718+ // Optional, available on clients as of v3.714.0.
719+ profile: " my-sso-profile" ,
720+ credentials: fromProcess ({
721+ // Optional. Defaults to the client's profile if that is set.
722+ // You can specify a profile here as well, but this applies
723+ // only to the credential resolution and not to the upper client.
724+ // Use this instead of the client profile if you need a separate profile
725+ // for credentials.
661726 profile: " my-sso-profile" ,
662727 // Optional. The path to the shared credentials file. If not specified, the provider will use
663728 // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of
@@ -778,10 +843,19 @@ messages be sent to the Instance Metadata Service
778843import { fromNodeProviderChain } from " @aws-sdk/credential-providers" ; // ES6 import
779844// const { fromNodeProviderChain } = require("@aws-sdk/credential-providers") // CommonJS import
780845const credentialProvider = fromNodeProviderChain ({
781- // ...any input of fromEnv(), fromSSO(), fromTokenFile(), fromIni(),
782- // fromProcess(), fromInstanceMetadata(), fromContainerMetadata()
783- // Optional. Custom STS client configurations overriding the default ones.
784- clientConfig: { region },
846+ // This provider accepts any input of fromEnv(), fromSSO(), fromTokenFile(),
847+ // fromIni(), fromProcess(), fromInstanceMetadata(), fromContainerMetadata()
848+ // that exist in the default credential chain.
849+
850+ // Optional client overrides. This is passed to an inner credentials client
851+ // that may be STS, SSO, or other instantiated to resolve the credentials.
852+ // Region and profile are inherited from the upper client if present
853+ // unless overridden, so it should not be necessary to set those.
854+ //
855+ // Warning: setting a region here may override the region set in
856+ // the config file for the selected profile if profile-based
857+ // credentials are used.
858+ clientConfig: {},
785859});
786860```
787861
@@ -799,7 +873,7 @@ All the providers from this package are compatible, and can be used to create su
799873As with _ any_ function provided to the ` credentials ` SDK client constructor configuration field, if the credential object returned does not contain
800874an ` expiration ` (type ` Date ` ), the client will only ever call the provider function once. You do not need to memoize this function.
801875
802- To enable automatic refresh, the credential provider function should set an ` expiration ` (` Date ` ) field. When this expiration approaches within 5 minutes, the
876+ To enable automatic refresh, the credential provider function should set an ` expiration ` (` Date ` ) field. When this expiration approaches within 5 minutes, the
803877provider function will be called again by the client in the course of making SDK requests.
804878
805879To assist with this, the ` createCredentialChain ` has a chainable helper ` .expireAfter(milliseconds: number) ` . An example is included below.
0 commit comments