Thursday, April 30, 2009

Create Image from existing instance and reuse to create a new instance

Often we need to create one production instance and another test instance for testing. Environment is similar for both instances. So if you are using Amazon ec2 then you can configure one instance and then create an image from that instance to reuse it to create another instance just like the first one.

Create volume from your instance

Copy pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem and cert-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem file into /mnt folder in your instance.

Note: You can download these files from your amazon account.

/mnt is not included in the image so your certification files will be secured and not stored in the image.

login to your instance and run in command line,

ec2-bundle-vol -d /mnt -k /mnt/pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem -c /mnt/cert-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem -u xxxxxxxxxxxx -r i386 -s 1536
Here,
–d => is the directory where the images will be generated
-k => privatekey PATH
-c => cert PATH
-u => your AWS account ID as your username (not your AWS Access Key ID)
-r => Specify target architecture. [i386, x86_64]
-s => The size, in MB (1024 * 1024 bytes), of the image file to create. The maximum size is 10240 MB
upload bundle into your s3 bucket

Then run,

ec2-upload-bundle -b 'your-s3-bucket' -m /mnt/image.manifest.xml -a 'aws-access-key-id' -s 'aws-secret-access-key' 
Register image

run

ec2-register 'your-s3-bucket'/image.manifest.xml

You should see some thing like this in the screen.

IMAGE   ami-xxxxxxxx

Note: You might not get this command from instance. For this you will need ec2 api tool in you instance or in your local machine.

You can download it from here.

Running Instances from your newly created image

run

ec2-run-instances ami-xxxxxxxx

You should see some thing like this in the screen.

RESERVATION     r-632db90a      106811649921    default
INSTANCE        i-xxxxxxxx      ami-xxxxxxxx                    pending
0               m1.small        2009-04-30T05:26:38+0000        us-east-1c

resources

http://docs.amazonwebservices.com/AmazonEC2/gsg/2006-06-26/creating-an-image.html

http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351

http://wiki.apache.org/hadoop/AmazonEC2[For publishing Image as public]

No comments: