Created
June 1, 2017 08:56
-
-
Save daxroc/4173792f79200db57296a24ce5600732 to your computer and use it in GitHub Desktop.
AWS ECS python script to export container IAM credentials for use with various tools
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
#!/usr/bin/env python | |
import os, urllib, json | |
uri = os.environ['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] | |
url = "http://169.254.170.2{}".format(uri) | |
data = json.loads(urllib.urlopen(url).read()) | |
print """export AWS_ACCESS_KEY_ID={AccessKeyId} | |
export AWS_SECRET_ACCESS_KEY={SecretAccessKey} | |
export AWS_SESSION_TOKEN={Token} | |
""".format(**data).strip() |
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
eval $(/usr/bin/awsenv.py) | |
# AWS envvars should now be set.. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment