Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache credentials across all clients #4612

Open
1 of 2 tasks
everett1992 opened this issue Apr 4, 2023 · 2 comments
Open
1 of 2 tasks

Cache credentials across all clients #4612

everett1992 opened this issue Apr 4, 2023 · 2 comments
Assignees
Labels
feature-request New feature or enhancement. May require GitHub community feedback. p2 This is a standard priority issue queued This issues is on the AWS team's backlog

Comments

@everett1992
Copy link
Contributor

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

@everett1992 everett1992 added feature-request New feature or enhancement. May require GitHub community feedback. needs-triage This issue or PR still needs to be triaged. labels Apr 4, 2023
@yenfryherrerafeliz yenfryherrerafeliz added p2 This is a standard priority issue needs-review This issue/pr needs review from an internal developer. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 10, 2023
@yenfryherrerafeliz
Copy link
Contributor

Hi @everett1992, thanks for opening this feature request. I will add the right labeling so this feature request gets into our backlog. However I want to mention that we prioritize our items based on different criteria, which also includes community reactions and comments. PRs are also welcomed.

Thanks!

@yenfryherrerafeliz yenfryherrerafeliz added queued This issues is on the AWS team's backlog and removed needs-review This issue/pr needs review from an internal developer. labels May 3, 2023
@1nstinct
Copy link

1nstinct commented Jan 12, 2024

Want to vote for this feature request too. Every new client the credentials are requested that is slowing down the getObject() process.
image

@kuhe kuhe self-assigned this Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or enhancement. May require GitHub community feedback. p2 This is a standard priority issue queued This issues is on the AWS team's backlog
Projects
None yet
Development

No branches or pull requests

4 participants