To create and save image from a running Instance : Amazon EC2

May 10, 2010 at 1:05 pm 5 comments

First, install Amazon’s AMI tools, and API tools: on your running instance:

1)mkdir /root/.ec2
2)export $EC2_TOOLS_DIR=/root/.ec2
3)mkdir ec2-ami-tools
4)cd ec2-ami-tools
7)ln -s ec2-ami-tools-* current
8)cd ..
9)mkdir ec2-api-tools
10)cd ec2-api-tools
11) wget
13)ln -s ec2-api-tools-* current
14)echo “export EC2_AMITOOL_HOME=`dirname $EC2_TOOLS_DIR`/ec2-ami-tools/current” >> ~/.bashrc
15)echo “export EC2_APITOOL_HOME=`dirname $EC2_TOOLS_DIR`/ec2-api-tools/current” >> ~/.bashrc
16)echo “export PATH=${PATH}:`dirname $AMI_TOOLS_DIR`/ec2-ami-tools/current/bin:`dirname $AMI_TOOLS_DIR`/ec2-api-tools/current/bin” >> ~/.bashrc
17)source ~/.bashrc

18)Next, you’ll need to get your security credentials. You can get a reminder of – or create as needed – these on the AWS “Your Account” > “Security Credentials” page.
Attached is the keys
19)You’ll also need to note your AWS access details – especially your access key and secret key – plus your Amazon account ID.

First, choose a name for your AMI snapshot. We’ll call it ami-instance-name 🙂
1.# make a directory for your image:
mkdir /mnt/ami-webserver-11march10
2.# create the image (this will take a while!)
ec2-bundle-vol -d /mnt/ami-instance-name -k /path/to/your/pk-(long string).pem -c /path/to/your/cert-(long string).pem -u YOUR_AMAZON_ACCOUNT_ID_WITHOUT_DASHES

Once that’s done, you should have a file called image.manifest.xml in your /mnt/ami-instance-name directory, along with all the bundle parts.

Next, upload the AMI image to S3. This command will create an S3 bucket of the given name if it doesn’t exist – I’ve found it convenient to call my buckets the same as the instance name:
1.ec2-upload-bundle -b ami-instance-name -m /mnt/ami-instance-name/image.manifest.xml -a YOUR_AWS_ACCESS_KEY -s YOUR_AWS_SECRET_KEY

You should then be able to register the instance from AWS Management Console web UI, but you can also do it from the command line using:
ec2-register ami-instance-name/image.manifest.xml

Copy your certificate and private key on mnt/ami-instance-name/amazon_cert

My .sh File

mkdir /mnt/images/$1
ec2-bundle-vol -d /mnt/images/$1 -k $EC2_PRIVATE_KEY -c $EC2_CERT -u $AWS_ACCOUNT_ID
ec2-upload-bundle -b $1 -m /mnt/images/$1/image.manifest.xml -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY
ec2-register $1/image.manifest.xml
.and giving it a parameter of ami-instance-name.script saved as, so I can just call, for instance:
./ webserver-name

After registarion of the image go and create instance from the same.. registered image

To Create instance from the image
Go to your amazon web console
select the image and create instance from the same.


Entry filed under: RoR, Uncategorized. Tags: , , , , , , , , , , , , .

berufliche und akademische einfach schreiben Analyse Zeitung Erstellen schreiben einer Hausarbeit Voruntersuchungen schriftliche Dokumente choose works internet from flourishing composition on the web business enterprise

5 Comments Add your own

  • 1. Prodosh  |  September 9, 2010 at 9:51 am

    Thanks for this fantastic post – it really explains everything.

    Are you available for consulting for AWS related infrastructure?

  • 3. a_[w]  |  December 24, 2010 at 6:24 am

    Thanks for this tutorial! It is very helpful, i’ve done everything as you described and have successfuly created a backup image.

  • 4. Jawwad  |  January 19, 2011 at 6:12 am

    if i want that i can take an AMI image automatically after 2 days and it will overwrite on my previous image. how can i configure this in AWS , kindly help me .

    • 5. neelmani  |  January 30, 2011 at 5:24 pm

      javed you can create a shell script for your job and add it in the cron job that can be run at any user defined time.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


May 2010
« Feb   Jul »

Most Recent Posts

%d bloggers like this: