Skip to content

Instantly share code, notes, and snippets.

@ohrite
Created October 25, 2011 00:55
Show Gist options
  • Save ohrite/1310980 to your computer and use it in GitHub Desktop.
Save ohrite/1310980 to your computer and use it in GitHub Desktop.
Profile includes for Elastic Beanstalk
for file in $(\ls -1 ${HOME}/.bash_profile_includes/*.sh); do
source $file;
done
# AWS Credential Management for the command line
# Useful in the context of the AWS Elastic Beanstalk CLI Tools
export AWS_CREDENTIAL_FILE=$HOME/.aws/current
# Assign a set of credentials to be the active file.
set_aws_credentials ()
{
local proposed="$HOME/.aws/$1"
if [ -e "$proposed" ]
then
if [ -e "$AWS_CREDENTIAL_FILE" ]
then
rm "$AWS_CREDENTIAL_FILE"
fi
ln -s "$proposed" "$AWS_CREDENTIAL_FILE"
else
echo "ERROR: Credentials for ${1} were not found."
exit 1
fi
}
# Write a new set of credentials to a file location.
# Providing -f as an argument overwrites existing credentials.
write_aws_credentials ()
{
if [ "$#" -eq 0 ]
then
echo <<-USAGE
Writes your AWS credentials for easy use by set_aws_credentials.
Usage:
write_aws_credentials [flags] your@aws.email
USAGE
exit 1
fi
case "$1" in
-f|--force)
force=true
shift
;;
esac
local proposed="$HOME/.aws/$1"
if [ ! -d "$HOME/.aws" ]
then
mkdir -p "$HOME/.aws"
fi
if [ -e "$proposed" ]
then
if force
then
mv "$proposed" "$proposed.bak"
else
echo "ERROR: Credentials for $1 already exist."
exit 1
fi
fi
printf "AWS Access ID: "
read id
printf "AWS Secret Key: "
read key
echo "AWSAccessKeyId=$id" > "$proposed"
echo "AWSSecretKey=$key" >> "$proposed"
chmod 0600 "$proposed"
set_aws_credentials "$1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment