AWS STS output saved to ~/.aws/credentials file
- MacOS / Linux
- Python 3.6+
- AWS CLI
pip install sts2credentials
aws sts assume-role \
--role-arn arn:aws:iam::123456789012:role/RoleYouWantToAssume \
--role-session-name SomeSessionName \
| sts2credentials
By default, sts2credentials
will write the credentials output by the aws sts
command in your ~/.aws/credentials
file, under a profile named sts
.
Behind the scene, sts2credentials
runs aws configure
commands to set the configuration.
Using the --profile
option will let you write into the profile name of your
choice.
aws sts assume-role ...
| sts2credentials --profile my-custom-profile
import boto3
from sts2credentials import configure_credentials
sts = boto3.client("sts")
response = sts.assume_role(...)
configure_credentials(response["Credentials"], profile="foo")
This tool has been inspired by this Stack Overflow answer: https://stackoverflow.com/a/57430760/1489984