Skip to content

Instantly share code, notes, and snippets.

@medwig
Created April 19, 2019 05:00
Show Gist options
  • Save medwig/0c48986baee90feb5b0b2989eaa103ca to your computer and use it in GitHub Desktop.
Save medwig/0c48986baee90feb5b0b2989eaa103ca to your computer and use it in GitHub Desktop.
Create aws credentials file from session token
PROFILE=foo
ACCOUNT_ID=123456
ROLE=terraform
aws sts assume-role --role-arn arn:aws:iam::$ACCOUNT_ID:role/$ROLE --role-session-name "foo" > token
aws configure --profile $PROFILE set aws_session_token $(jq < token '.Credentials.SessionToken' -r)
aws configure --profile $PROFILE set aws_access_key_id $(jq < token '.Credentials.AccessKeyId' -r)
aws configure --profile $PROFILE set aws_secret_access_key $(jq < token '.Credentials.SecretAccessKey' -r)
tail ~/.aws/credentials
aws sts get-caller-identity --profile $PROFILE
sls info --aws-profile $PROFILE
@medwig
Copy link
Author

medwig commented Apr 19, 2019

On a build server the Serverless Framework won't be able to find the credentials for a command like:
$ sls deploy --aws-profile foo

This script assumes a role in the target aws profile (account) and uses it's temporary credentials to make a profile that --aws-profile can understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment