Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fetch AWS credentials for CLI usage via Wormhole
#!/bin/bash
# reconfigure AWS CLI credentials
set -e
function requires() {
if ! command -v $1 &>/dev/null; then
echo "Requires $1"
exit 1
fi
}
function usage() {
echo "Usage: $0 ACCOUNT" >&2
exit 1
}
function fail() {
echo "error: $@" >&2
exit 1
}
CURL=$(brew --prefix curl)/bin/curl
requires jq
requires ${CURL}
requires aws
case $1 in
dev)
account="DEV_ACCOUNT_NUMBER";;
live)
account="LIVE_ACCOUNT_NUMBER";;
*)
usage
esac
creds_json=$(${CURL} -s --cert ~/.cert/cert.pem https://wormhole.api.bbci.co.uk/account/${account}/credentials) || fail failed to fetch credentials from aws wormhole
accessKeyId=$(jq -r '.accessKeyId' <<< "${creds_json}")
secretAccessKey=$(jq -r '.secretAccessKey' <<< "${creds_json}")
sessionToken=$(jq -r '.sessionToken' <<< "${creds_json}")
echo "Got details for access key ${accessKeyId}"
aws configure set aws_access_key_id "${accessKeyId}"
aws configure set aws_secret_access_key "${secretAccessKey}"
aws configure set aws_session_token "${sessionToken}"
aws configure set region "eu-west-1"
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.