aws-sdk (Golang): Session expirations?

I’m learning about how sessions work in the aws-sdk package for Go. One thing I’m unsure of is how Sessions work. The documentation states that they are objects that “contains configuration information for service clients. which you use to interact with AWS services.”.

What I’m unsure about is how ephemeral these sessions are. For example, do these sessions need to be recreated/refreshed after a certain period of time? And if so, is this by default, or something you manually set?

Any other general info on Sessions would be appreciated. I’m probably missing something here.

I can’t speak exclusively for go, but under boto3 (python SDK) you make a session when you need to pick a non standard profile or override the region or similar. It probably works the same way under the GO SDK if it’s the same class name.

So if I did…

S3 = boto3.client(“s3”)

It would use the default profile but I could override that by doing

S3 = boto3.Session(profile_name=“work-gamma-ro”).client(“s3”)

Or by doing…

session = boto3.Session(profile_name=“work-gamma-ro”)
s3 = session.client(“s3”)

And it would use the “work-gamma-ro” profile setup from my ~/.AWS/config and ~/.AWS/credentials files. That last style is nice because if I also need services other than s3 I can re use the same session object without having to specify it multiple times.

You don’t have to refresh them or anything, it just denotes that you’re overriding the defaults

I always assumed the SDK would just handle this for me, and I think it does just that. Why worry, unless it’s a problem?

Many assumable roles do have a timeout (default 60-120 minutes I think?) where you’d have to refresh it and go get another session token.

If OP is writing a wrapper, say for unorthodox CLI auth methods, they’d need to take this into account.

While true, there’s typically ways around that to have the SDKs refresh the creds for you. For example just having a profile that specifies role_arn gives you auto-refreshing creds as long as you have permission to use the role otherwise. It’s a good callout, but there’s mitigations