Created
December 15, 2017 00:35
-
-
Save idooo/b579229bfe29c97594c54ae0fa94adf9 to your computer and use it in GitHub Desktop.
STS Assume role script helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Requirements: | |
# brew install jq | |
# | |
# Launch: | |
# Executing script will print environment variables (eg "~/src/assume-role.sh 983056893078 OrganizationAccountAccessRole master") | |
# Use "." in bash if you want to export them to a current session | |
# (eg: . ~/src/assume-role.sh 12312312313 OrganizationAccountAccessRole master) | |
unset AWS_SESSION_TOKEN | |
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
ACCOUNT_ID=$1 | |
ROLE=$2 | |
PROFILE=$3 | |
HOSTNAME=$(hostname) | |
temp_role=$(aws sts assume-role \ | |
--role-arn "arn:aws:iam::$ACCOUNT_ID:role/$ROLE" \ | |
--role-session-name "$HOSTNAME-$ROLE" \ | |
--profile $PROFILE) | |
export AWS_ACCESS_KEY_ID=$(echo $temp_role | jq .Credentials.AccessKeyId | xargs) | |
export AWS_SECRET_ACCESS_KEY=$(echo $temp_role | jq .Credentials.SecretAccessKey | xargs) | |
export AWS_SESSION_TOKEN=$(echo $temp_role | jq .Credentials.SessionToken | xargs) | |
env | grep -i AWS_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment