Skip to content

Instantly share code, notes, and snippets.

@daxroc
Created June 1, 2017 08:56
Show Gist options
  • Save daxroc/4173792f79200db57296a24ce5600732 to your computer and use it in GitHub Desktop.
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
#!/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()
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