What is the expected lifetime of cfg
and svc
instances?
#2566
Replies: 1 comment 1 reply
-
I would classify service clients as rather lightweight in this SDK. That said you do generally want to keep client instances around simply because of credential provision. If you're on a platform like EC2 or EKS, where credential provision requires network calls, you can save repeated instances of those calls because the client will cache credentials until they expire. This is not a hard rule though, just know that this is something to consider.
No - we explicitly designate clients to be goroutine-safe
Just credentials. The SDK automatically refreshes credentials where dynamic refresh is possible. Dynamic refresh is possible for all sources minus environment and shared config. In general, if you're deploying software to a compute environment where long-running applications are possible (e.g. EC2) credential refresh is automatic. |
Beta Was this translation helpful? Give feedback.
-
Hi. I have a general question about config and service instances. Consider the initialization code, as seen in many examples:
My application will list and retrieve objects from S3 frequently. Should create a new
cfg
andsvc
instance with each call? Or should I create them on application startup and reuse those instances for every call?It seems to work either way, but I'm not sure about:
svc
instance?cfg
orsvc
instance keep any tokens that might expire?Any other thoughts would be useful, and I would hope the docs would be updated to explain this better also. Thanks.
Update: I did see this doc, which seems to indicate reusing service clients is thread-safe. But it doesn't really answer my other concerns. I'm mostly concerned about whether it's safe to keep the service client for a long period of time (days, weeks, etc.). Will it refresh its own authentication automatically? And is this advised? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions