@aws-sdk/credential-providers 3.918.0 → 3.920.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,26 +7,29 @@ A collection of all credential providers.
7
7
 
8
8
  # Table of Contents
9
9
 
10
- 1. [Terminology](#terminology)
11
- 1. [From Cognito Identity](#fromcognitoidentity)
12
- 1. [From Cognito Identity Pool](#fromcognitoidentitypool)
13
- 1. [From Temporary Credentials](#fromtemporarycredentials)
14
- 1. [From Web Token](#fromwebtoken)
15
- 1. [Examples](#examples)
16
- 1. [From Token File](#fromtokenfile)
17
- 1. [From Instance and Container Metadata Service](#fromcontainermetadata-and-frominstancemetadata)
18
- 1. [From HTTP(S)](#fromhttp)
19
- 1. [From Shared INI files](#fromini)
20
- 1. [Sample Files](#sample-files)
21
- 1. [From Environmental Variables](#fromenv)
22
- 1. [From Credential Process](#fromprocess)
23
- 1. [Sample files](#sample-files-1)
24
- 1. [From Single Sign-On Service](#fromsso)
25
- 1. [Supported Configuration](#supported-configuration)
26
- 1. [SSO login with AWS CLI](#sso-login-with-the-aws-cli)
27
- 1. [Sample Files](#sample-files-2)
28
- 1. [From Node.js default credentials provider chain](#fromnodeproviderchain)
29
- 1. [Creating a custom credentials chain](#createcredentialchain)
10
+ - [Terminology](#terminology)
11
+ - [Credentials Provider](#credentials-provider)
12
+ - [Outer and inner clients](#outer-and-inner-clients)
13
+ - [Resolving AWS Region in credential providers (e.g. STS region)](#resolving-aws-region-in-credential-providers-eg-sts-region)
14
+ - [From Cognito Identity](#fromcognitoidentity)
15
+ - [From Cognito Identity Pool](#fromcognitoidentitypool)
16
+ - [From Temporary Credentials](#fromtemporarycredentials)
17
+ - [From Web Token](#fromwebtoken)
18
+ - [Examples](#examples)
19
+ - [From Token File](#fromtokenfile)
20
+ - [From Instance and Container Metadata Service](#fromcontainermetadata-and-frominstancemetadata)
21
+ - [From HTTP(S)](#fromhttp)
22
+ - [From Shared INI files](#fromini)
23
+ - [Sample Files](#sample-files)
24
+ - [From Environmental Variables](#fromenv)
25
+ - [From Credential Process](#fromprocess)
26
+ - [Sample files](#sample-files-1)
27
+ - [From Single Sign-On Service](#fromsso)
28
+ - [Supported Configuration](#supported-configuration)
29
+ - [SSO login with AWS CLI](#sso-login-with-the-aws-cli)
30
+ - [Sample Files](#sample-files-2)
31
+ - [From Node.js default credentials provider chain](#fromnodeproviderchain)
32
+ - [Creating a custom credentials chain](#createcredentialchain)
30
33
 
31
34
  ## Terminology
32
35
 
@@ -59,6 +62,17 @@ An `AwsCredentialIdentityProvider` is any function that matches the signature:
59
62
  }>;
60
63
  ```
61
64
 
65
+ That is, an async function which returns an object containing AWS credentials.
66
+
67
+ Whether you write your own such function or use one of the providers from this package, when used in
68
+ conjunction with an AWS SDK Client, the client will cache the resulting credentials
69
+ until there is less than 5 minutes remaining to their expiration, at which point the
70
+ function will be called again, and the new credentials cached.
71
+
72
+ This is designed to minimize the number of credential requests. Each client
73
+ instance has a separate cache of credentials, so if you want to share credential caching
74
+ between clients, you'll need to implement your own cache outside the SDK.
75
+
62
76
  #### Outer and inner clients
63
77
 
64
78
  A "parent/outer/upper/caller" (position), or "data" (purpose) client refers
@@ -80,6 +94,77 @@ In the above example, `S3Client` is the outer client, and
80
94
  if the `fromIni` credentials provider uses STS::AssumeRole, the
81
95
  `STSClient` initialized by the SDK is the inner client.
82
96
 
97
+ ## Resolving AWS Region in credential providers (e.g. STS region)
98
+
99
+ When a credential provider uses an SDK client to retrieve credentials, commonly STS, the
100
+ control of the STS region follows this logic:
101
+
102
+ ```js
103
+ import { fromIni } from "@aws-sdk/credential-providers";
104
+
105
+ /*
106
+ # AWS config file contents
107
+ [profile default]
108
+ region = profile-region
109
+ role_arn = ROLE_ARN
110
+ source_profile = assume
111
+
112
+ [profile assume]
113
+ ...
114
+ */
115
+
116
+ process.env.AWS_REGION = "env-region";
117
+
118
+ const provider = fromIni({
119
+ clientConfig: {
120
+ region: "credential-provider-config-region",
121
+ },
122
+ });
123
+
124
+ const client = new SDKClient({
125
+ region: "context-client-region",
126
+ credentials: provider,
127
+ });
128
+
129
+ const fallbackRegion = "us-east-1";
130
+ ```
131
+
132
+ As shown above, there are many sources of region information. The priority order is:
133
+
134
+ 1. `credential-provider-config-region` - given in code to the credential provider itself.
135
+ 2. `profile-region` **\*** - if credential provider is resolving credentials from the config file, the config file's
136
+ region takes precedence in this case over AWS_REGION env.
137
+ 3. `context-client-region` - the region resolved by an SDK client using the credential provider.
138
+ 4. `env-region` - AWS_REGION environment variable.
139
+ 5. `profile-region` **\*** - if credential provider is not resolving credentials from the config file, the config file's
140
+ region is lower priority than AWS_REGION env.
141
+ 6. `us-east-1` (fallback) - this is a legacy fallback value. It's more likely that the client will fail to execute any
142
+ operation if none of the other region sources were set.
143
+
144
+ This differs from _direct_ instantiation of the STSClient, which follows this order, which is the same for all clients:
145
+
146
+ ```js
147
+ import { STSClient } from "@aws-sdk/client-sts";
148
+ /*
149
+ # AWS config file contents
150
+ [profile default]
151
+ region = profile-region
152
+ */
153
+
154
+ process.env.AWS_REGION = "env-region";
155
+
156
+ const client = new STSClient({
157
+ region: "client-region",
158
+ });
159
+ ```
160
+
161
+ 1. `client-region`
162
+ 2. `env-region`
163
+ 3. `profile-region` (config file)
164
+ 4. thrown error (no us-east-1 fallback)
165
+
166
+ # Credential providers
167
+
83
168
  ## `fromCognitoIdentity()`
84
169
 
85
170
  - Uses `@aws-sdk/client-cognito-identity`
@@ -91,7 +176,6 @@ for more information.
91
176
 
92
177
  ```javascript
93
178
  import { fromCognitoIdentity } from "@aws-sdk/credential-providers"; // ES6 import
94
- // const { fromCognitoIdentity } = require("@aws-sdk/credential-providers"); // CommonJS import
95
179
 
96
180
  const client = new FooClient({
97
181
  region,
@@ -133,7 +217,6 @@ Results from `GetId` are cached internally, but results from `GetCredentialsForI
133
217
 
134
218
  ```javascript
135
219
  import { fromCognitoIdentityPool } from "@aws-sdk/credential-providers"; // ES6 import
136
- // const { fromCognitoIdentityPool } = require("@aws-sdk/credential-providers"); // CommonJS import
137
220
 
138
221
  const client = new FooClient({
139
222
  region,
@@ -178,7 +261,6 @@ credentials from [STS AssumeRole API][assumerole_api].
178
261
 
179
262
  ```javascript
180
263
  import { fromTemporaryCredentials } from "@aws-sdk/credential-providers"; // ES6 import
181
- // const { fromTemporaryCredentials } = require("@aws-sdk/credential-providers"); // CommonJS import
182
264
 
183
265
  const client = new FooClient({
184
266
  region,
@@ -217,12 +299,11 @@ const client = new FooClient({
217
299
  - Uses `@aws-sdk/client-sts`
218
300
  - Available in browsers & native apps
219
301
 
220
- The function `fromWebToken` returns `AwsCredentialIdentityProvider` that gets credentials calling
302
+ The function `fromWebToken` returns an `AwsCredentialIdentityProvider` that gets credentials calling
221
303
  [STS AssumeRoleWithWebIdentity API][assumerolewithwebidentity_api]
222
304
 
223
305
  ```javascript
224
306
  import { fromWebToken } from "@aws-sdk/credential-providers"; // ES6 import
225
- // const { fromWebToken } = require("@aws-sdk/credential-providers"); // CommonJS import
226
307
 
227
308
  const client = new FooClient({
228
309
  region,
@@ -292,7 +373,6 @@ read from the ECS container metadata service and the EC2 instance metadata servi
292
373
 
293
374
  ```javascript
294
375
  import { fromInstanceMetadata } from "@aws-sdk/credential-providers"; // ES6 import
295
- // const { fromInstanceMetadata } = require("@aws-sdk/credential-providers"); // CommonJS import
296
376
 
297
377
  const client = new FooClient({
298
378
  credentials: fromInstanceMetadata({
@@ -308,7 +388,6 @@ const client = new FooClient({
308
388
 
309
389
  ```javascript
310
390
  import { fromContainerMetadata } from "@aws-sdk/credential-providers"; // ES6 import
311
- // const { fromContainerMetadata } = require("@aws-sdk/credential-providers"); // CommonJS import
312
391
 
313
392
  const client = new FooClient({
314
393
  credentials: fromContainerMetadata({
@@ -322,12 +401,12 @@ const client = new FooClient({
322
401
  });
323
402
  ```
324
403
 
325
- A `AwsCredentialIdentityProvider` function created with `fromContainerMetadata` will return a promise that will
404
+ An `AwsCredentialIdentityProvider` function created with `fromContainerMetadata` will return a promise that will
326
405
  resolve with credentials for the IAM role associated with containers in an Amazon ECS task. Please
327
406
  see [IAM Roles for Tasks][iam_roles_for_tasks] for more information on using IAM roles with Amazon
328
407
  ECS.
329
408
 
330
- A `AwsCredentialIdentityProvider` function created with `fromInstanceMetadata` will return a promise that will
409
+ An `AwsCredentialIdentityProvider` function created with `fromInstanceMetadata` will return a promise that will
331
410
  resolve with credentials for the IAM role associated with an EC2 instance.
332
411
  Please see [IAM Roles for Amazon EC2][iam_roles_for_ec2] for more information on using IAM roles
333
412
  with Amazon EC2. Both IMDSv1 (a request/response method) and IMDSv2 (a session-oriented method) are
@@ -369,7 +448,6 @@ Node.js:
369
448
 
370
449
  ```js
371
450
  import { fromHttp } from "@aws-sdk/credential-providers";
372
- // const { fromHttp } = require("@aws-sdk/credential-providers");
373
451
 
374
452
  const client = new FooClient({
375
453
  credentials: fromHttp({
@@ -454,7 +532,6 @@ credentials file will be given precedence over the profile found in the config f
454
532
 
455
533
  ```javascript
456
534
  import { fromIni } from "@aws-sdk/credential-providers"; // ES6 import
457
- // const { fromIni } = require("@aws-sdk/credential-providers"); // CommonJS import
458
535
 
459
536
  const client = new FooClient({
460
537
  // As of v3.714.0, an easy way to select a profile is to set it on the client.
@@ -597,14 +674,13 @@ See [`fromSSO()`](#fromsso) for more information
597
674
 
598
675
  ```javascript
599
676
  import { fromEnv } from "@aws-sdk/credential-providers"; // ES6 import
600
- // const { fromEnv } = require("@aws-sdk/credential-providers"); // CommonJS import
601
677
 
602
678
  const client = new FooClient({
603
679
  credentials: fromEnv(),
604
680
  });
605
681
  ```
606
682
 
607
- `fromEnv` returns a `AwsCredentialIdentityProvider` function, that reads credentials from the following
683
+ `fromEnv` returns an `AwsCredentialIdentityProvider` function, that reads credentials from the following
608
684
  environment variables:
609
685
 
610
686
  - `AWS_ACCESS_KEY_ID` - The access key for your AWS account.
@@ -624,7 +700,6 @@ contains a falsy value, the promise returned by the `fromEnv` function will be r
624
700
 
625
701
  ```javascript
626
702
  import { fromProcess } from "@aws-sdk/credential-providers"; // ES6 import
627
- // const { fromProcess } = require("@aws-sdk/credential-providers"); // CommonJS import
628
703
 
629
704
  const client = new FooClient({
630
705
  // Optional, available on clients as of v3.714.0.
@@ -647,7 +722,7 @@ const client = new FooClient({
647
722
  });
648
723
  ```
649
724
 
650
- `fromSharedConfigFiles` creates a `AwsCredentialIdentityProvider` functions that executes a given process and
725
+ `fromProcess` creates an `AwsCredentialIdentityProvider` functions that executes a given process and
651
726
  attempt to read its standard output to receive a JSON payload containing the credentials. The
652
727
  process command is read from a shared credentials file at `~/.aws/credentials` and a shared
653
728
  configuration file at `~/.aws/config`. Both files are expected to be INI formatted with section
@@ -706,7 +781,6 @@ The function `fromTokenFile` returns `AwsCredentialIdentityProvider` that reads
706
781
 
707
782
  ```javascript
708
783
  import { fromTokenFile } from "@aws-sdk/credential-providers"; // ES6 import
709
- // const { fromTokenFile } = require("@aws-sdk/credential-providers"); // CommonJS import
710
784
 
711
785
  const client = new FooClient({
712
786
  region: "us-west-2",
@@ -714,8 +788,8 @@ const client = new FooClient({
714
788
  // Optional overrides. This is passed to an inner STS client
715
789
  // instantiated to resolve the credentials. Region is inherited
716
790
  // from the upper client if present unless overridden.
717
- clientConfig: {}
718
- });
791
+ clientConfig: {},
792
+ }),
719
793
  });
720
794
  ```
721
795
 
@@ -747,12 +821,11 @@ function. You can either load the SSO config from shared INI credential files, o
747
821
 
748
822
  ```javascript
749
823
  import { fromSSO } from "@aws-sdk/credential-providers"; // ES6 import
750
- // const { fromSSO } = require("@aws-sdk/credential-providers") // CommonJS import
751
824
 
752
825
  const client = new FooClient({
753
826
  // Optional, available on clients as of v3.714.0.
754
827
  profile: "my-sso-profile",
755
- credentials: fromProcess({
828
+ credentials: fromSSO({
756
829
  // Optional. Defaults to the client's profile if that is set.
757
830
  // You can specify a profile here as well, but this applies
758
831
  // only to the credential resolution and not to the upper client.
@@ -876,7 +949,7 @@ messages be sent to the Instance Metadata Service
876
949
 
877
950
  ```js
878
951
  import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; // ES6 import
879
- // const { fromNodeProviderChain } = require("@aws-sdk/credential-providers") // CommonJS import
952
+
880
953
  const credentialProvider = fromNodeProviderChain({
881
954
  // This provider accepts any input of fromEnv(), fromSSO(), fromTokenFile(),
882
955
  // fromIni(), fromProcess(), fromInstanceMetadata(), fromContainerMetadata()
@@ -898,20 +971,26 @@ const credentialProvider = fromNodeProviderChain({
898
971
 
899
972
  You can use this helper to create a credential chain of your own.
900
973
 
901
- A credential chain is created from a list of functions of the signature () => Promise<[AwsCredentialIdentity](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-smithy-types/Interface/AwsCredentialIdentity/)>,
974
+ A credential chain is created from a list of functions of the signature () =>
975
+ Promise<[AwsCredentialIdentity](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-smithy-types/Interface/AwsCredentialIdentity/)>,
902
976
  composed together such that the overall chain has the **same** signature.
903
977
 
904
- That is why you can provide the chained credential provider to the same field (`credentials`) as any single provider function.
978
+ That is why you can provide the chained credential provider to the same field (`credentials`) as any single provider
979
+ function.
905
980
 
906
981
  All the providers from this package are compatible, and can be used to create such a chain.
907
982
 
908
- As with _any_ function provided to the `credentials` SDK client constructor configuration field, if the credential object returned does not contain
909
- an `expiration` (type `Date`), the client will only ever call the provider function once. You do not need to memoize this function.
983
+ As with _any_ function provided to the `credentials` SDK client constructor configuration field, if the credential
984
+ object returned does not contain
985
+ an `expiration` (type `Date`), the client will only ever call the provider function once. You do not need to memoize
986
+ this function.
910
987
 
911
- To enable automatic refresh, the credential provider function should set an `expiration` (`Date`) field. When this expiration approaches within 5 minutes, the
988
+ To enable automatic refresh, the credential provider function should set an `expiration` (`Date`) field. When this
989
+ expiration approaches within 5 minutes, the
912
990
  provider function will be called again by the client in the course of making SDK requests.
913
991
 
914
- To assist with this, the `createCredentialChain` has a chainable helper `.expireAfter(milliseconds: number)`. An example is included below.
992
+ To assist with this, the `createCredentialChain` has a chainable helper `.expireAfter(milliseconds: number)`. An example
993
+ is included below.
915
994
 
916
995
  ```ts
917
996
  import { fromEnv, fromIni, createCredentialChain } from "@aws-sdk/credential-providers";
@@ -25,13 +25,12 @@ const createCredentialChain = (...credentialProviders) => {
25
25
  exports.createCredentialChain = createCredentialChain;
26
26
  const propertyProviderChain = (...providers) => async (awsIdentityProperties) => {
27
27
  if (providers.length === 0) {
28
- throw new property_provider_1.ProviderError("No providers in chain");
28
+ throw new property_provider_1.ProviderError("No providers in chain", { tryNextLink: false });
29
29
  }
30
30
  let lastProviderError;
31
31
  for (const provider of providers) {
32
32
  try {
33
- const credentials = await provider(awsIdentityProperties);
34
- return credentials;
33
+ return await provider(awsIdentityProperties);
35
34
  }
36
35
  catch (err) {
37
36
  lastProviderError = err;
@@ -21,13 +21,12 @@ export const createCredentialChain = (...credentialProviders) => {
21
21
  };
22
22
  export const propertyProviderChain = (...providers) => async (awsIdentityProperties) => {
23
23
  if (providers.length === 0) {
24
- throw new ProviderError("No providers in chain");
24
+ throw new ProviderError("No providers in chain", { tryNextLink: false });
25
25
  }
26
26
  let lastProviderError;
27
27
  for (const provider of providers) {
28
28
  try {
29
- const credentials = await provider(awsIdentityProperties);
30
- return credentials;
29
+ return await provider(awsIdentityProperties);
31
30
  }
32
31
  catch (err) {
33
32
  lastProviderError = err;
@@ -1,4 +1,4 @@
1
- import { FromSSOInit } from "@aws-sdk/credential-provider-sso";
1
+ import { fromSSO as _fromSSO } from "@aws-sdk/credential-provider-sso";
2
2
  import { AwsCredentialIdentityProvider } from "@smithy/types";
3
3
  /**
4
4
  * Creates a credential provider function that reads from the _resolved_ access token from local disk then requests
@@ -43,4 +43,4 @@ import { AwsCredentialIdentityProvider } from "@smithy/types";
43
43
  *
44
44
  * @public
45
45
  */
46
- export declare const fromSSO: (init?: FromSSOInit) => AwsCredentialIdentityProvider;
46
+ export declare const fromSSO: (init?: Parameters<typeof _fromSSO>[0]) => AwsCredentialIdentityProvider;
@@ -1,5 +1,5 @@
1
- import { FromSSOInit } from "@aws-sdk/credential-provider-sso";
1
+ import { fromSSO as _fromSSO } from "@aws-sdk/credential-provider-sso";
2
2
  import { AwsCredentialIdentityProvider } from "@smithy/types";
3
3
  export declare const fromSSO: (
4
- init?: FromSSOInit
4
+ init?: Parameters<typeof _fromSSO>[0]
5
5
  ) => AwsCredentialIdentityProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/credential-providers",
3
- "version": "3.918.0",
3
+ "version": "3.920.0",
4
4
  "description": "A collection of credential providers, without requiring service clients like STS, Cognito",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -31,18 +31,18 @@
31
31
  },
32
32
  "license": "Apache-2.0",
33
33
  "dependencies": {
34
- "@aws-sdk/client-cognito-identity": "3.918.0",
35
- "@aws-sdk/core": "3.916.0",
36
- "@aws-sdk/credential-provider-cognito-identity": "3.918.0",
37
- "@aws-sdk/credential-provider-env": "3.916.0",
38
- "@aws-sdk/credential-provider-http": "3.916.0",
39
- "@aws-sdk/credential-provider-ini": "3.918.0",
40
- "@aws-sdk/credential-provider-node": "3.918.0",
41
- "@aws-sdk/credential-provider-process": "3.916.0",
42
- "@aws-sdk/credential-provider-sso": "3.916.0",
43
- "@aws-sdk/credential-provider-web-identity": "3.918.0",
44
- "@aws-sdk/nested-clients": "3.916.0",
45
- "@aws-sdk/types": "3.914.0",
34
+ "@aws-sdk/client-cognito-identity": "3.920.0",
35
+ "@aws-sdk/core": "3.920.0",
36
+ "@aws-sdk/credential-provider-cognito-identity": "3.920.0",
37
+ "@aws-sdk/credential-provider-env": "3.920.0",
38
+ "@aws-sdk/credential-provider-http": "3.920.0",
39
+ "@aws-sdk/credential-provider-ini": "3.920.0",
40
+ "@aws-sdk/credential-provider-node": "3.920.0",
41
+ "@aws-sdk/credential-provider-process": "3.920.0",
42
+ "@aws-sdk/credential-provider-sso": "3.920.0",
43
+ "@aws-sdk/credential-provider-web-identity": "3.920.0",
44
+ "@aws-sdk/nested-clients": "3.920.0",
45
+ "@aws-sdk/types": "3.920.0",
46
46
  "@smithy/config-resolver": "^4.4.0",
47
47
  "@smithy/core": "^3.17.1",
48
48
  "@smithy/credential-provider-imds": "^4.2.3",