Release Management/Amazon Use Cases
Contents |
Introduction.
As some day or the other we (RM) all have either shifted our existing EC2 instances or oncreased the space etc. etc. So decided to write a wiki/refernce for later use.
Use Cases
There are several schenarios which we have dealt with in past:
- Created a clone of our existing instance.
- Increasing space in one of the EBS devices (eg. /dev/sda1 or /dev/sdh)
- Migrating instance from "Instance Store" to "EBS".
etc. etc.
Steps For Use Cases
- Created a clone of our existing instance.
Solution:
- Create a fresh volume.
ec2-create-volume -s SIZE -z ZONE example: ec2-create-volume -s 50 -z eu-west-1b
- Attaching the volume to an instance.
ec2-attach-volume VOLUME -i INSTANCE -d DEVICE example: ec2-attach-volume vol-b4cc21d0 -i i-b079f3c0 -d /dev/sdh
- Format the volume and mount it on some directory.
mkfs.ext3 DEVICE mount DEVICE DIRECTORY example: mkfs.ext3 /dev/sdh example: mount /dev/sdh /mnt/ebs
- Rsync the data.
rsync -avHx FROM_DIRECTORY TO_DIRECTORY example: rsync -avHx /srv/ /mnt/ebs
- Unmount the volume.
umount /dev/sdh
- Detaching the volume from an instance.
ec2-detach-volume VOLUME example: ec2-detach-volume vol-b4cc21d0
- Create a snapshot of existing volume.
ec2-create-snapshot -d DESCRIPTION VOLUME_ID example: ec2-create-snapshot -d "Creating new Instance for Test" vol-b4cc21d0
- Register an AMI from a snapshot.
ec2-register -s SNAPSHOT_ID --kernel AKI --description DESCRIPTION --architecture ARCH -n NAME --root-device-name ROOT_DEVICE example: ec2-register -s snap-fc803495 --kernel aki-966a41e2 --description "New AMI for Testing" --architecture i386 --root-device-name /dev/sda1
- Boot an instance from an AMI.
ec2-run-instances -k $KEYPAIR-EU -t INSTANCE_TYPE -g $SECURITY_GROUP $AMI example: ec2-run-instances -k harpreet-eu -t c1.medium -g tmp ami-f8795280
- Increasing space in one of the EBS devices (eg. /dev/sda1 or /dev/sdh)
- Migrating instance from "Instance Store" to "EBS".
Solution:
EC2 CLI Commands
All these commands are written keeping in mind that your ENV variables are set (EC2 key/userID/api-tools etc)
A) Creating a volume.
- Creating a fresh volume.
ec2-create-volume -s SIZE -z ZONE example: ec2-create-volume -s 50 -z eu-west-1b
- Creating volume from a snapshot
ec2-create-volume --snapshot SNAPSHOT -s SIZE -z ZONE example: ec2-create-volume --snapshot snap-fc803495 -s 50 -z eu-west-1b
B) Creating a snapshot of existing volume.
ec2-create-snapshot -d DESCRIPTION VOLUME_ID example: ec2-create-snapshot -d "Creating new Instance for Test" vol-b4cc21d0
C) Registering an AMI from a snapshot.
ec2-register -s SNAPSHOT_ID --kernel AKI --description DESCRIPTION --architecture ARCH -n NAME --root-device-name ROOT_DEVICE example: ec2-register -s snap-fc803495 --kernel aki-966a41e2 --description "New AMI for Testing" --architecture i386 --root-device-name /dev/sda1
D) Booting an instance from an AMI.
ec2-run-instances -k $KEYPAIR-EU -t INSTANCE_TYPE -g $SECURITY_GROUP $AMI example: ec2-run-instances -k harpreet-eu -t c1.medium -g tmp ami-f8795280
E) Detaching a volume from an instance.
ec2-detach-volume VOLUME example: ec2-detach-volume vol-b4cc21d0
F) Attaching a volume to an instance.
ec2-attach-volume VOLUME -i INSTANCE -d DEVICE example: ec2-attach-volume vol-b4cc21d0 -i i-b079f3c0 -d /dev/sdh
G) Stopping an instance.
ec2-stop-instances INSTANCE example: ec2-stop-instances i-b079f3c0
H) Rebooting an instance.
ec2-reboot-instances INSTANCE example: ec2-reboot-instances i-b079f3c0
I) Terminating an instance.
ec2-terminate-instances INSTANCE example: ec2-terminate-instances i-b079f3c0
J)
example: