Closed stanhu closed 2 months ago
Hi @stanhu,
Our developer guide talks about this:
All credential providers passed to or returned by LoadDefaultConfig are wrapped in a CredentialsCache automatically. This enables caching and concurrency safe credential access. If you explicitly configure a provider on aws.Config directly you must explicitly wrap the provider with this type using NewCredentialsCache.
Regarding your question:
Is it okay to cache s3.Client indefinitely? I presume that when the credentials are expired, it will automatically refresh them.
If you are using LoadDefaultConfig
then yes. The same is true for Go SDK v1's session.NewSession()
. Both instruct the SDK to use the default credential provider chain, which automatically comes with a cache that handles credential rotation for any of the providers. In your case, the SDK would make calls to IMDS to refresh credentials 5 min before the credentials' expiration window.
This isn't covered in the migration guide because the functionality in v1 and v2 is the same with regards to how credentials are rotated. The only difference is the re-naming of the config object, which in v1 was confusingly named "session" even though it does not really represent a session but rather a config object.
I suppose we can add another section in the migration guide about the credential rotation behavior.
Thanks, Ran~
@RanVaknin Thanks, that helps clarify things!
I suppose we can add another section in the migration guide about the credential rotation behavior.
Yes, that would be helpful.
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.
Describe the issue
In https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html, the guidance for caching
s3.Session
was clear:In https://aws.github.io/aws-sdk-go-v2/docs/migrating/ and https://aws.github.io/aws-sdk-go-v2/docs/making-requests/, I'm not clear on what could be cached. We have a long-lived application that might make hundreds of S3 calls over time, and we want to avoid hitting STS limits. If I understand correctly:
In this example:
1.
config.LoadDefaultConfig
: I think this might make a HTTP request to the instance metadata or STS endpoint if no static credentials are configured.s3.Client
: This creates a new S3 client and loads the credentials from the config.Is it okay to cache
s3.Client
indefinitely? I presume that when the credentials are expired, it will automatically refresh them.It should also be okay to cache
config.LoadDefaultConfig
to avoid making an HTTP call, but it might just be easier to caches3.Client
.It'd be nice to update the documentation, especially in the migration guide, about this behavior.
Links
AWS Go SDK V2 Module Versions Used