Skip to content

Cache credentials across all clientsΒ #4612

@everett1992

Description

@everett1992

Describe the feature

In sdk v3 CredentialProviders are not internally cached1. Each time you call a credential provider it refreshes credentials from it's source. This causes workflows that use multiple aws services to take longer as each client fetches the same credentials from the source.

const creds = fromProcess()
await creds() // executes the process
await creds() // executes the process again

Each client caches credentials by wrapping the provider in memoize, but memoize does not cache across instances.

const client = new  S3({ creds })
await client.listObjects({}) // calls credential provider
await client.listObjects({}) // uses cached credentials

new  S3({ creds }).listObjects({}) // calls credential provider again!

Credential providers should use a cache shared across all clients.

Use Case

const credentials = fromProcess()
const sqs = new SQS({ credentials })
const ddb = new DynamoDB({ credentials })

await ddb.createTable({...})   // blocks fetching credentials
await sqs.sendMessage({...}) // blocks fetching the same credentials 

The use case is any workflow that involves creating multiple aws-sdk clients that use the same credentials or identity. This workflow should only fetch credentials once, not once per client.

Proposed Solution

A couple options:

  1. change the memoize wrapper to use a global cache. I think this could be done simply by moving these variables into a WeakMap keyed by provider. so each memoized provider instance would use the same cached values.
  2. memoize the CredentialProviders provided by @aws-sdk/credential-providers (like fromNodeProviderChain is already)
  3. Add documentation and inform users that they should memoize the credential provider they use
const credentials = memoize(fromProcess())

Option 1 works with aws-sdk authored credential providers as well as user defined providers.
Option 2 would only work out of the box with aws authored providers
Option 3 would only work when users read the docs

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

SDK version used

~3.300

Environment details (OS name and version, etc.)

All

Footnotes

  1. except the default node provider chain ↩

Metadata

Metadata

Assignees

Labels

feature-requestNew feature or enhancement. May require GitHub community feedback.p2This is a standard priority issuequeuedThis issues is on the AWS team's backlog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions