Created
February 11, 2021 14:29
-
-
Save AstroTom/c1c44cb161a4535d815838991575e04e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# | |
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
# You must use 'source' to run this file, otherwise it has no effect | |
# Alternately, you can put it in .bashrc | |
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
# e.g. | |
# $ source credentials.sh | |
# | |
# | |
# use this script to get the AWS temporary STS credentials from the | |
# Instance metadata sevice | |
# | |
# Note this key will expire after a few hours so you may need to rerun to get a new one | |
# | |
role_name=$( curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/ ) | |
creds_json=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${role_name}) | |
export AWS_ACCESS_KEY_ID=$(echo "$creds_json" | jq .AccessKeyId |tr -d '"') | |
export AWS_SECRET_ACCESS_KEY=$(echo "$creds_json" | jq .SecretAccessKey| tr -d '"') | |
export AWS_SESSION_TOKEN=$(echo "$creds_json" | jq .Token|tr -d '"') | |
export AWS_DEFAULT_REGION=eu-west-1 | |
export SERVICE_REGION=$AWS_DEFAULT_REGION # used by python ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment