@@ -51,33 +51,16 @@ providers, you can set up the SDK to get credentials for the IAM role using help
51
51
52
52
``` javascript
53
53
import { DynamoDBClient } from " @aws-sdk/client-dynamodb" ;
54
- import { STSClient , AssumeRoleWithWebIdentityCommand } from " @aws-sdk/client-sts" ;
54
+ import { getDefaultRoleAssumerWithWebIdentity } from " @aws-sdk/client-sts" ;
55
55
import { fromWebToken } from " @aws-sdk/credential-provider-web-identity" ;
56
56
57
- const stsClient = new STSClient ({});
58
-
59
- const roleAssumerWithWebIdentity = async (params ) => {
60
- const { Credentials } = await stsClient .send (
61
- new AssumeRoleWithWebIdentityCommand (params)
62
- );
63
- if (! Credentials || ! Credentials .AccessKeyId || ! Credentials .SecretAccessKey ) {
64
- throw new Error (` Invalid response from STS.assumeRole call with role ${ params .RoleArn } ` );
65
- }
66
- return {
67
- accessKeyId: Credentials .AccessKeyId ,
68
- secretAccessKey: Credentials .SecretAccessKey ,
69
- sessionToken: Credentials .SessionToken ,
70
- expiration: Credentials .Expiration ,
71
- };
72
- };
73
-
74
57
const dynamodb = new DynamoDBClient ({
75
58
region,
76
59
credentials: fromWebToken ({
77
60
roleArn: ' arn:aws:iam::<AWS_ACCOUNT_ID>/:role/<WEB_IDENTITY_ROLE_NAME>' ,
78
61
providerId: ' graph.facebook.com|www.amazon.com' , // this is null for Google
79
62
webIdentityToken: ACCESS_TOKEN // from OpenID token identity provider
80
- roleAssumerWithWebIdentity,
63
+ roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity () ,
81
64
})
82
65
});
83
66
@@ -117,29 +100,12 @@ The following options are supported:
117
100
A basic example of using fromTokenFile:
118
101
119
102
``` js
120
- import { STSClient , AssumeRoleWithWebIdentityCommand } from " @aws-sdk/client-sts" ;
103
+ import { getDefaultRoleAssumerWithWebIdentity } from " @aws-sdk/client-sts" ;
121
104
import { fromTokenFile } from " @aws-sdk/credential-provider-web-identity" ;
122
105
123
- const stsClient = new STSClient ({});
124
-
125
- const roleAssumerWithWebIdentity = async (params ) => {
126
- const { Credentials } = await stsClient .send (
127
- new AssumeRoleWithWebIdentityCommand (params)
128
- );
129
- if (! Credentials || ! Credentials .AccessKeyId || ! Credentials .SecretAccessKey ) {
130
- throw new Error (` Invalid response from STS.assumeRole call with role ${ params .RoleArn } ` );
131
- }
132
- return {
133
- accessKeyId: Credentials .AccessKeyId ,
134
- secretAccessKey: Credentials .SecretAccessKey ,
135
- sessionToken: Credentials .SessionToken ,
136
- expiration: Credentials .Expiration ,
137
- };
138
- };
139
-
140
106
const client = new FooClient ({
141
107
credentials: fromTokenFile ({
142
- roleAssumerWithWebIdentity
108
+ roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity ()
143
109
});
144
110
});
145
111
```
@@ -167,7 +133,7 @@ const client = new FooClient({
167
133
credentials: fromTokenFile ({
168
134
webIdentityTokenFile: " /temp/token" ,
169
135
roleArn: " arn:aws:iam::123456789012:role/example-role-arn" ,
170
- roleAssumerWithWebIdentity
136
+ roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity ()
171
137
});
172
138
});
173
139
```
0 commit comments