Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Last active August 24, 2019 19:02
Show Gist options
  • Save KyMidd/842cf75705aeccb782c30b9b3c44bc0d to your computer and use it in GitHub Desktop.
Save KyMidd/842cf75705aeccb782c30b9b3c44bc0d to your computer and use it in GitHub Desktop.
# Assume role
aws sts assume-role --role-arn arn:aws:iam::$ACCOUNT_ID:role/AzureDevOpsAssumedIamRole --role-session-name "BuilderHostname=$INSTANCE_ID" > mysession.json
# Extract values from session, write to disk
jq -r '.Credentials.AccessKeyId' mysession.json | awk '{print "export", "AWS_ACCESS_KEY_ID="$0}' > variables
jq -r '.Credentials.SecretAccessKey' mysession.json | awk '{print "export", "AWS_SECRET_ACCESS_KEY="$0}' >> variables
jq -r '.Credentials.SessionToken' mysession.json | awk '{print "export", "AWS_SESSION_TOKEN="$0}' >> variables
# Read variables into global
. ./variables
# Delete variables file on disk
rm variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment