Last active
December 18, 2015 11:49
-
-
Save eentzel/5778905 to your computer and use it in GitHub Desktop.
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/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