Creating a snapshot of instance on EC2

A good article with detailed instructions can be found here.
I only had to change paths in ~/.bashrc. Instead of /root I used /home/ec2-user/.
I also excluded quotation marks in the lines with “echo” command.
I registered instance using Amazon web interface. The article describes how to do it using API as well. I created the script also with help from here.
I put into my /root/.bashrc the following lines:

export EC2_PRIVATE_KEY=/mnt/keys/pk-(long string).pem
export EC2_CERT=/mnt/keys/cert-(long string).pem
export AWS_ACCOUNT_ID=(my account id)
export AWS_ACCESS_KEY=(my AWS access key)
export AWS_SECRET_KEY=(my AWS secret key)

Script named make_ami.sh has following lines:

#!/bin/bash
# script makes a snopshot of instance, uploads it to AWS-S3 and registers it on AWS
$AMI_NAME=$1
mkdir -p /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
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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