-
-
Save dhobbs/d85a3fb2c6a223537feb to your computer and use it in GitHub Desktop.
Export IAM credentials as environment variables
This file contains 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 | |
# download jq from http://stedolan.github.io/jq/ | |
IAM_CREDS=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/[iam-role] 2>/dev/null` | |
export AWS_ACCESS_KEY_ID=`echo $IAM_CREDS | jq .AccessKeyId | sed -e 's/^"//' -e 's/"$//'` | |
export AWS_SECRET_ACCESS_KEY=`echo $IAM_CREDS | jq .SecretAccessKey | sed -e 's/^"//' -e 's/"$//'` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source this file from an EC2 instance with an IAM role (replace [iam-role] with the name of your role) to get the credentials as environment variables, for tools that don't understand IAM.
(IAM credentials are short-lived, so you'll want to run this immediately before the thing that needs the variables).