##AWS CLI Credentials for MFA Accounts ##
With MFA enabled accounts, you need to generate session tokens (via STS) to use the AWS CLI tools.
- Python 2.7.8
- AWS CLI
- CLI configured with '~/.aws/config' containing header for each environment
- config.py file that contains a dictionary AWS_ACCOUNTS where key is $ENVRIRONMENT and value is $AWS_ACCOUNT_ID
Example config.py file
AWS_ACCOUNTS = { 'dev': '123456789012', 'prd': '123456789013' }
Example ~/.aws/config file
[profile init_$ENVIRONMENT]
aws_access_key_id = $AWS_ACCESS_KEY_ID
aws_secret_access_key = $AWS_SECRET_ACCESS_KEY
The script will use the credentials for init_$ENVIRONMENT and create a new profile named "profile $ENVIRONMENT".
[profile $ENVIRONMENT]
aws_access_key_id = $AWS_ACCESS_KEY_ID
aws_secret_access_key = $AWS_SECRET_ACCESS_KEY
$ python get_sts_token.py -u kevin.dimichel --mfa_token 123456 -e prd
$ python get_sts_token.py -u kevin.dimichel-dev --mfa_token 123456 -e dev
$ aws iam list-roles --profile dev