Skip to content

Commit 5f99930

Browse files
committed
docs(credential-provider-web-identity): update README
1 parent a2935a8 commit 5f99930

File tree

1 file changed

+5
-39
lines changed
  • packages/credential-provider-web-identity

1 file changed

+5
-39
lines changed

packages/credential-provider-web-identity/README.md

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,16 @@ providers, you can set up the SDK to get credentials for the IAM role using help
5151

5252
```javascript
5353
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
54-
import { STSClient, AssumeRoleWithWebIdentityCommand } from "@aws-sdk/client-sts";
54+
import { getDefaultRoleAssumerWithWebIdentity } from "@aws-sdk/client-sts";
5555
import { fromWebToken } from "@aws-sdk/credential-provider-web-identity";
5656

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-
7457
const dynamodb = new DynamoDBClient({
7558
region,
7659
credentials: fromWebToken({
7760
roleArn: 'arn:aws:iam::<AWS_ACCOUNT_ID>/:role/<WEB_IDENTITY_ROLE_NAME>',
7861
providerId: 'graph.facebook.com|www.amazon.com', // this is null for Google
7962
webIdentityToken: ACCESS_TOKEN // from OpenID token identity provider
80-
roleAssumerWithWebIdentity,
63+
roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity(),
8164
})
8265
});
8366

@@ -117,29 +100,12 @@ The following options are supported:
117100
A basic example of using fromTokenFile:
118101

119102
```js
120-
import { STSClient, AssumeRoleWithWebIdentityCommand } from "@aws-sdk/client-sts";
103+
import { getDefaultRoleAssumerWithWebIdentity } from "@aws-sdk/client-sts";
121104
import { fromTokenFile } from "@aws-sdk/credential-provider-web-identity";
122105

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-
140106
const client = new FooClient({
141107
credentials: fromTokenFile({
142-
roleAssumerWithWebIdentity
108+
roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity()
143109
});
144110
});
145111
```
@@ -167,7 +133,7 @@ const client = new FooClient({
167133
credentials: fromTokenFile({
168134
webIdentityTokenFile: "/temp/token",
169135
roleArn: "arn:aws:iam::123456789012:role/example-role-arn",
170-
roleAssumerWithWebIdentity
136+
roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity()
171137
});
172138
});
173139
```

0 commit comments

Comments
 (0)