Skip to content

Instantly share code, notes, and snippets.

@heldeen
Last active August 29, 2015 14:21
Show Gist options
  • Save heldeen/d50490d9d57d1bed2203 to your computer and use it in GitHub Desktop.
Save heldeen/d50490d9d57d1bed2203 to your computer and use it in GitHub Desktop.
Simple script for AWS STS, cross account access. You need this because you understand the security concerns and have a separate account for your production site, right?
aws sts assume-role --role-arn "arn:aws:iam::<ACCOUNT_ID>:path/to/yourProdRole" \
--role-session-name "session-reason" \
--query "Credentials.{AccessKeyId,SecretAccessKey,SessionToken}" \
--output text | awk 'BEGIN {print "[default]";} { print "aws_access_key_id =",$1,"\naws_secret_access_key =",$2,"\naws_session_token =",$3,"\naws_security_token =",$3; }' > ~/.aws/credentials.tmp
# wait for the AWS CLI to finish before we copy the file into place
sleep 5
cp ~/.aws/credentials ~/.aws/credentials.bak
cp ~/.aws/credentials.tmp ~/.aws/credentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment