Managing multiple AWS accounts
On my personal computer, I have three sets of x509 certificates/private keys. This makes using the EC2-API-tools quite the hassle. Echoes of EC2_CERT and EC2_PRIVATE_KEY haunt my dreams.
So, like you do with these sort of things, I wrote a bash script to work some magic.
#!/bin/bash
echo "Choose Account:"
read account
base=grep $account ~/.ec2/README -i | awk '{print $1}'
if [ ! -n "$base" ]; then
echo "Sorry, that account does not exist"
return
fi
declare -x EC2_CERT="~/.ec2/cert-$base.pem"
declare -x EC2_PRIVATE_KEY="~/.ec2/pk-$base.pem"
echo "EC2 environment updated"
Requires that you your private keys/certs in ~/.ec2, and they are named cert-{something}.pem and pk-{something}.pem. Also, you need a README file in ~/.ec2 that looks like
something account1
something-else account2
I setup an alias so I just run “ec2-account personal” to switch to my personal credentials, and “ec2-account work” to switch to my work account.
-David