I have a Go program which uses shared SSO authentication. The program itself works fine, but I need to start a nested program from it (docker), and this program needs the AWS credentials from the main program.
I use AWS SDK v2.
How can I export my current credentials as environment variables?
I understand that I can use assumeRole, like this:
credentials, err := ssoClient.GetRoleCredentials(context.TODO(), &sso.GetRoleCredentialsInput{ AccountId: aws.String(accountID), RoleName: aws.String(roleName), }) but that would be wrong, because I have no role to assume; I just want to use my current user.
Another possible solution could be parsing ~/.aws/cli/cache/*.json manually, but this solutions looks too low level and hacky (but probably it is the only one, at least I didn't manage to find anything better).
~/.aws/sso/cache.» Looking at this, I see that the token obtained from the SSO cache gets decoded into plainaws.Credentials, so seems like you can just export them as is.nilinto this function, though internally it can handle nil values properly. There should be some better way, I think...