Skip to content

Instantly share code, notes, and snippets.

@AstroTom
Created February 11, 2021 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AstroTom/c1c44cb161a4535d815838991575e04e to your computer and use it in GitHub Desktop.
Save AstroTom/c1c44cb161a4535d815838991575e04e to your computer and use it in GitHub Desktop.
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# 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