Skip to content

Commit 6fd6269

Browse files
authored
docs(UPGRADING): on the use of expiration in credential provider functions (#5961)
1 parent 58875c9 commit 6fd6269

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

UPGRADING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ This list is indexed by [v2 config parameters](https://docs.aws.amazon.com/AWSJa
3636
- **v3**: No change.
3737
- [`credentials`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#credentials-property)
3838
- **v2**: The AWS credentials to sign requests with.
39-
- **v3**: No change. It can also be an async function that returns credentials.
39+
- **v3**: No change. It can also be an async function that returns credentials. If the function returns an `expiration (Date)`, the function will
40+
be called again when the expiration datetime nears.
4041
See [v3 reference for AwsAuthInputConfig credentials](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/interfaces/_aws_sdk_middleware_signing.awsauthinputconfig-1.html#credentials).
4142
- [`endpointCacheSize`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#endpointCacheSize-property)
4243
- **v2**: The size of the global cache storing endpoints from endpoint discovery operations.

supplemental-docs/CLIENTS.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,17 @@ import { fromCognitoIdentity } from "@aws-sdk/credential-providers";
135135
const client = new S3Client({
136136
credentials: async () => {
137137
// get credentials from any source.
138+
const credentials = {
139+
/* ... */
140+
};
138141
return {
139-
accessKeyId: "...",
140-
secretAccessKey: "...",
141-
sessionToken: "...",
142+
accessKeyId: credentials.accessKeyId,
143+
secretAccessKey: "etc.",
144+
sessionToken: "etc.",
145+
// 1. You can set an expiration near which this function will be called again.
146+
// 2. You can use the expiration given by your upstream credentials provider, if it exists.
147+
// 3. Omitting an expiration will result in this function not being called more than once.
148+
expiration: new Date(),
142149
};
143150
},
144151
});
@@ -340,11 +347,12 @@ const client = new DynamoDBClient({
340347
requestHandler: new NodeHttpHandler({
341348
requestTimeout: 3_000,
342349
httpsAgent: new https.Agent({
343-
maxSockets: 25
350+
maxSockets: 25,
344351
}),
345352
}),
346353
});
347354
```
355+
348356
```ts
349357
// Example: short form requestHandler configuration.
350358
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
@@ -356,8 +364,9 @@ const client = new DynamoDBClient({
356364
},
357365
});
358366
```
367+
359368
You can instead pass the constructor parameters directly. The default requestHandler for the platform and service will be used.
360-
For Node.js, most services use `NodeHttpHandler`. For browsers, most services use `FetchHttpHandler`.
369+
For Node.js, most services use `NodeHttpHandler`. For browsers, most services use `FetchHttpHandler`.
361370

362371
Kinesis, Lex Runtime v2, QBusiness, TranscribeStreaming use `NodeHttp2Handler` by default instead in Node.js.
363372
RekognitionStreaming and TranscribeStreaming use the `WebSocketFetchHandler` by default instead in browsers.

0 commit comments

Comments
 (0)