Last active
December 21, 2015 07:28
-
-
Save NitriKx/6270900 to your computer and use it in GitHub Desktop.
[Old CLI Tool] Create an aws-credential-file based on EC2 instance role.
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 | |
ROLE=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/` | |
JSON=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${ROLE}` | |
AWS_ACCESS_KEY=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'AccessKeyId' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'` | |
AWS_SECRET_KEY=`echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w 'SecretAccessKey' | cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'` | |
echo "AWSAccessKeyId=${AWS_ACCESS_KEY}" > /tmp/aws_credentials | |
echo "AWSSecretKey=${AWS_SECRET_KEY}" >> /tmp/aws_credentials |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment