Skip to content

Instantly share code, notes, and snippets.

@Pindar
Created March 5, 2014 16: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 Pindar/9370682 to your computer and use it in GitHub Desktop.
Save Pindar/9370682 to your computer and use it in GitHub Desktop.
extract temporary aws keys
#!/bin/bash
# requires http://stedolan.github.io/jq/
AWS_ROLE_NAME=`wget -O - -q 'http://169.254.169.254/latest/meta-data/iam/security-credentials/'`
wget -O mycreds -q "http://169.254.169.254/latest/meta-data/iam/security-credentials/$AWS_ROLE_NAME"
SECRET_KEY=`jq -r '.SecretAccessKey' <mycreds`
ACCESS_KEY=`jq -r '.AccessKeyId' <mycreds`
TOKEN=`jq -r '.Token' <mycreds`
cat >temp_credentials <<EOM
AWSAccessKeyId=$ACCESS_KEY
AWSSecretKey=$SECRET_KEY
SecurityToken=$TOKEN
EOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment