Skip to content

Instantly share code, notes, and snippets.

@wilhelm-murdoch
Created July 7, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilhelm-murdoch/8a8f7eb8276c9a64170793d0e0e40219 to your computer and use it in GitHub Desktop.
Save wilhelm-murdoch/8a8f7eb8276c9a64170793d0e0e40219 to your computer and use it in GitHub Desktop.
Docker-based AWS CLI
#!/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