Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspotton/eb91610f5e60521bb67a4d016ee7a917 to your computer and use it in GitHub Desktop.
Save aspotton/eb91610f5e60521bb67a4d016ee7a917 to your computer and use it in GitHub Desktop.
Support using boto v2 in a task under Amazon ECS
#!/bin/bash
# Boto v2 doesn't use the AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variable when running under Amazon ECS
# as a task, making it fail to find the AWS security credentials. This will export the ENV variables that Boto expects
# to find and is a suitable workaround.
CREDS=`curl 169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`
export AWS_ACCESS_KEY_ID=`echo -n $CREDS | python2 -m json.tool | grep AccessKeyId | awk '{print $2}' | sed 's/[",]//g'`
export AWS_SECRET_ACCESS_KEY=`echo -n $CREDS | python2 -m json.tool | grep SecretAccessKey | awk '{print $2}' | sed 's/[",]//g'`
export AWS_SECURITY_TOKEN=`echo -n $CREDS | python2 -m json.tool | grep Token | awk '{print $2}' | sed 's/[",]//g'`
export AWS_SESSION_TOKEN=`echo -n $CREDS | python2 -m json.tool | grep Token | awk '{print $2}' | sed 's/[",]//g'`
# now you can execute your container entry point ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment