Skip to content

Instantly share code, notes, and snippets.

@eentzel
Last active December 18, 2015 11:49
Show Gist options
  • Save eentzel/5778905 to your computer and use it in GitHub Desktop.
Save eentzel/5778905 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
CREDENTIAL_FILE=~/.aws-creds
PROFILE_NAME=${1:-"default"}
SECTION=$(grep -A 3 "\[${PROFILE_NAME}\]" ${CREDENTIAL_FILE})
CREDENTIAL_LINES=$(echo "$SECTION" |
grep "^\(aws_access_key_id\|aws_secret_access_key\|region\)=")
EXPORT_LINES=$(echo "$CREDENTIAL_LINES" |
sed 's/aws_access_key_id=/export AWS_ACCESS_KEY_ID=/' |
sed 's/aws_secret_access_key=/export AWS_SECRET_ACCESS_KEY=/' |
sed 's/region=/export AWS_DEFAULT_REGION=/')
if [ `echo "$EXPORT_LINES" | wc -l` != "3" ]; then
echo "Unable to find profile ${PROFILE_NAME} in ${CREDENTIAL_FILE}" 1>&2
exit 1
fi
echo "$EXPORT_LINES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment