Created
May 26, 2017 20:52
-
-
Save bhyde/3944c00f9e812c188d0e7075634e2308 to your computer and use it in GitHub Desktop.
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 | |
# Run the AWS cli on an ec2 instance with the security credentials of that instance | |
set -e | |
export IAM_ROLE=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/) | |
export AWS_ACCESS_KEY_ID=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${IAM_ROLE} |/usr/bin/jq -r .AccessKeyId) | |
export AWS_SECRET_ACCESS_KEY=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${IAM_ROLE} |/usr/bin/jq -r .SecretAccessKey) | |
export AWS_SECURITY_TOKEN=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${IAM_ROLE} |/usr/bin/jq -r .Token) | |
export AWS_DEFAULT_REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/[a-z]$//') | |
# cat <<EOF | |
# IAM_ROLE $IAM_ROLE | |
# AWS_ACCESS_KEY_ID $AWS_ACCESS_KEY_ID | |
# AWS_SECRET_ACCESS_KEY $AWS_SECRET_ACCESS_KEY | |
# AWS_SECURITY_TOKEN $AWS_SECURITY_TOKEN | |
# EOF | |
exec /usr/bin/aws "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment