Skip to content

Instantly share code, notes, and snippets.

@stibi
Created September 20, 2017 13:33
Show Gist options
  • Save stibi/3800b60c5f6b9ed56734973ce6056499 to your computer and use it in GitHub Desktop.
Save stibi/3800b60c5f6b9ed56734973ce6056499 to your computer and use it in GitHub Desktop.
#/bin/bash
set -euo pipefail
instance_profile=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/)
aws_access_key_id=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep AccessKeyId | cut -d':' -f2 | sed 's/[^0-9A-Z]*//g')
aws_secret_access_key=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep SecretAccessKey | cut -d':' -f2 | sed 's/[^0-9A-Za-z/+=]*//g')
token=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | sed -n '/Token/{p;}' | cut -f4 -d'"')
export AWS_ACCESS_KEY_ID=${aws_access_key_id}
export AWS_SECRET_ACCESS_KEY=${aws_secret_access_key}
export AWS_SESSION_TOKEN=${token}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment