Created
August 14, 2017 16:30
-
-
Save kjhosein/e46c30369ef78834ee69d4f8fb978a08 to your computer and use it in GitHub Desktop.
Get temporary AWS credentials from instance profile
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
#!/bin/bash | |
# Get temporary AWS credentials as granted in the Instance Profile. | |
# | |
# Run it 'sourced'. i.e.: | |
# . ./get-temp-creds.sh | |
# | |
# Requires: jq | |
# | |
# Written Aug 2017 by Khalid J Hosein | |
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} | jq -r .AccessKeyId) | |
AWS_SECRET_ACCESS_KEY=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | jq -r .SecretAccessKey) | |
AWS_SESSION_TOKEN=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | jq -r .Token) | |
echo -e "\n Check that the following environment variables contain AWS access keys and token." | |
set | grep AWS | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment