Since both AMI storage and running Instance will cost you money, at least they will if and when you are no longer in the free tier which expires after one year, and for just plain practical reasons, you want a quick and easy way to see all your AMIs stored in the cloud and all your running instances.
One way to do that on the command line is with the aws cli.
for r in `aws ec2 describe-regions | jq -j '.[][] | .RegionName,"\t"'`;do echo "REGION: $r"; echo "================== Images:"; aws ec2 describe-images --region $r --owner self --output text; echo "===============+ Snapshots"; aws ec2 describe-snapshots --owner-ids self | jq -j '.Snapshots[]|.SnapshotId,"\n"'; echo "================== Instances:"; aws ec2 describe-instances --region $r --output text; doneSo, i can run that now as
ec2-describe-allto see the below output:
REGION: us-east-1 ================== Images: ================== Instances: REGION: us-west-2 ================== Images: ================== Instances: INSTANCE i-b25923ba ami-b8f69f88 ec2-54-187-9-244.us-west-2.compute.amazonaws.com ip-172-31-15-11.us-west-2.compute.internal running aws_rsa 0t1.micro 2014-04-07 REGION: us-west-1 ================== Images: ================== Instances:
Now I can rest assured, at least for the US regions I know what all my stored AMIs and running EC2 instances are in one easy command. Modify the script to do other regions or filter for other things as useful to you, like make a ec2-describe-all-intl script or ec2-describe-all-eu script.
Now that we have a default AMI from Amazon's stock of linux AMI images, let's customize it as the next step in our path to owning our own custom base AMIs.
ssh into the instance using it's IP address is simplyssh ec2-user@54.187.9.244 -i ~/.ssh/aws_rsaThen i install tomcat7 with
sudo yum install "tomcat7*"I can mess around with the config of tomcat a little, but ultimately this will be automated in an install config tool like chef and puppet, but that will be later. For now I just spent 5 minutes setting up a tomcat admin account and services defaults so tomcat would always be running and left it started up. This will become our new custom AMI, but we have to save it first, don't we?
ec2-describe-instancesthen run the create image command.
ec2-create-image -name tomcat7 i-b25923ba