Auto-generate AWS credentials file from AWS SSO?

Viewed 9

I use AWS Single Sign-ON (SSO) to get programmatic access keys to our various AWS accounts (production, staging, dev, etc) that I can then use on the command line.

I often need to hop between multiple environments so I need to manually add several sets of credentials to my /.aws/credentials file one at a time from the SSO page.

This isn't the biggest problem but is inconvenient/irritating as it takes time; has to be done a few times a day as the tokens expire; and the profile name included on the individual ~/.aws/credentials snippet has to be manually changed to the account name (e.g. [dev]) rather than the account number and SSO identity that AWS includes by default (e.g. [123456789012_AWSReadOnlyAccess]) so it works with our other tools (in this case Terraform workspaces).

I'd like a way to autogenerate user-friendly content for my ~/.aws/credentials easily covering all the SSO accounts I use day to day.

Is there such a facility/tool/script?

1 Answers

I couldn't find an existing example of something I could use to do this, so I put together this gist which is a bookmarklet that adds a button the AWS SSO landing page that, when clicked, will generate the ~/.aws/credentials content and copy it to the clipboard ready to use!

https://gist.github.com/bennyrw/4c6b18221611332605ea91474ae04f10

I hope it helps someone with the same problem I had :)

Related