This will tell you step by step how to create a Amazon AWS ec2 AMI image.
It presumes you know all about ec2, know what an AMI is and have followed the previous required guides.
You need to be comfortable with running an ec2 instance.
Obviously you need an instance to make an image from,
and I will assume this is an Ubuntu one similar to my ubuntu server tips.
You need to be set up with S3, and have a backup plan and a bucket for AMIs beforehand.
Check my backup page for S3 tips.
Basically if your instance is booted and running from the default assigned disk or booted and running directly from an EBS store. This guide will assume instance boot.
How to make an image of an EBS boot will be made soon. (Basically you take a snapshot of it and some extra steps, the AWS console automates this for you)
Change commands below if any different.
Steps you need to do before hand. But only once.
Local |
---|
|
vi ~/.ec2/accessKeys.txt
|
|
export AWS_ACCESS_KEY_ID=awsAccessKey |
|
gpg -r yourGpgEmailId -e ~/.ec2/accessKeys.txt; |
Step by step commands to do every time you want to make an AMI. Which you should do at regular intervals and definetly after evey major change to your instance. (Having a good backup and EBS strategy reduces this frequency.)
Remote/ec2 instance to backup | Local | Remote/ec2 new instance image |
---|---|---|
ssh -i .ec2/yourAwsKey ubuntu@publicDNSname
|
||
cd /mnt; |
||
scp -i .ec2/yourAwsKey .ec2/*.pem ubuntu@publicDNSname:/mnt/ec2/
|
||
vi ec2/api |
||
gpg -d .ec2/accessKeys.txt.gpg |
||
|
||
|
||
source ec2/api; |
||
Shut down any services, e.g. Apache, Postfix, etc. (Depends on what is running on your instance) Here are a couple of examples: |
||
sudo /etc/init.d/apache2 stop;
|
||
Unmount any EBS,
if any are attached to this instance. Here are a couple of examples: |
||
sudo umount /mnt/www;
|
||
|
||
sudo ec2-bundle-vol -d /mnt/bundle/ \ |
||
|
||
|
||
s3cmd.rb createbucket s3bucket
|
||
|
||
ec2-upload-bundle -b s3bucket \ |
||
|
||
|
||
ssh -i .ec2/yourAwsKey ubuntu@publicDNSnameOfNewImage
|
||
|
||
sudo shutdown -h now
|
||
|
||
sudo rm -rf ec2 bundle |
||
|
||
|
Voila!
Any issues or comments, refer to my feedback :)
head back to flurdy's ec2 docs for more ec2 tips and howtos?