Skip to content

Instantly share code, notes, and snippets.

@pwillis-els
Created July 22, 2019 21:24
Show Gist options
  • Save pwillis-els/aff9d0cd9bd32b396355aecb280d85e3 to your computer and use it in GitHub Desktop.
Save pwillis-els/aff9d0cd9bd32b396355aecb280d85e3 to your computer and use it in GitHub Desktop.
Get IAM access key from AWS EC2 instance profile metadata
#!/bin/sh
set -e
AWS_INST_PROFILE=$(curl -sL http://169.254.169.254/latest/meta-data/iam/security-credentials/ | tail)
curl -sL http://169.254.169.254/latest/meta-data/iam/security-credentials/${AWS_INST_PROFILE} \
| python -c 'import sys,json;j=json.load(sys.stdin);print("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n" % (j["AccessKeyId"],j["SecretAccessKey"]))'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment