Created
April 8, 2020 20:51
-
-
Save aspotton/eb91610f5e60521bb67a4d016ee7a917 to your computer and use it in GitHub Desktop.
Support using boto v2 in a task under Amazon ECS
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 | |
# 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