Skip to content

Instantly share code, notes, and snippets.

@PavelVanecek
Created September 16, 2015 14:48
Show Gist options
  • Save PavelVanecek/49761662fc237ba8f6c0 to your computer and use it in GitHub Desktop.
Save PavelVanecek/49761662fc237ba8f6c0 to your computer and use it in GitHub Desktop.
#!/bin/bash
CONF_FILE=~/.aws/credentials
function usage {
echo "Export AWS API keys"
echo "Will read $CONF_FILE and export the api keys as environment variables"
echo "Usage: $0 --profile <profile>"
}
# read parameters
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
usage
exit 0
;;
-p|--profile)
PROFILE="$2"
shift
;;
esac
shift
done
if [ -z "$PROFILE" ]; then
usage
exit 1
fi
cat "$CONF_FILE" |\
grep -F "[$PROFILE]" -A3 |\
tail -n+2 |\
sed "s/aws_security_token=\(.*\)/aws_security_token=\1\naws_session_token=\1/" |\
sed "s/\([^=]*\)=/export \U\1=/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment