Skip to content

Instantly share code, notes, and snippets.

@jonascheng
Created August 1, 2016 14:18
Show Gist options
  • Save jonascheng/0c2f3661a640326d36742ca13decccdc to your computer and use it in GitHub Desktop.
Save jonascheng/0c2f3661a640326d36742ca13decccdc to your computer and use it in GitHub Desktop.
#!/bin/bash
AWS_BASE_DIR=~/.aws
CREDENTIALS_DIR=$AWS_BASE_DIR/credentials.csv
function aws-credentials {
name=$1
if [[ -z $name ]]; then
echo "Syntax: aws-credentials <name>"
echo "where ~/.aws/credentials.csv/<name>.csv is an IAM credentials file."
echo "Available credentials:"
pushd $CREDENTIALS_DIR > /dev/null
for f in *; do
echo " $(echo $f | cut -d. -f1)"
done
popd > /dev/null
return 1
fi
credential_file=$CREDENTIALS_DIR/$name.csv
if [[ ! -f $credential_file ]]; then
echo "$credential_file does not exist."
return 1
fi
IFS=, read username access_key secret_key < \
<(tail -n 1 $credential_file | sed 's/"//g')
export AWS_ACCESS_KEY=$access_key
export AWS_SECRET_KEY=$secret_key
export AWS_ACCESS_KEY_ID=$access_key
export AWS_SECRET_ACCESS_KEY=$secret_key
export AWS_CREDENTIAL_FILE=$credential_file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment