Created
July 7, 2020 06:53
-
-
Save wilhelm-murdoch/8a8f7eb8276c9a64170793d0e0e40219 to your computer and use it in GitHub Desktop.
Docker-based AWS CLI
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 bash | |
set -eo pipefail | |
[[ -n "${VERBOSE}" ]] && set -x | |
metadata() { | |
curl -s --connect-timeout 2 --fail "http://169.254.169.254/latest/meta-data/$*" | |
} | |
role=$(metadata iam/info | jq -r .InstanceProfileArn | cut -d"/" -f2) | |
creds=$(metadata "iam/security-credentials/${role}") | |
export AWS_ACCESS_KEY_ID=$(echo $creds | jq -r .AccessKeyId) | |
export AWS_SECRET_ACCESS_KEY=$(echo $creds | jq -r .SecretAccessKey) | |
export AWS_SECURITY_TOKEN=$(echo $creds | jq -r .Token) | |
aws() { | |
docker run --rm \ | |
--env=AWS_ACCESS_KEY_ID \ | |
--env=AWS_SECRET_ACCESS_KEY \ | |
--env=AWS_SECURITY_TOKEN \ | |
amazon/aws-cli $* | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment