Sei sulla pagina 1di 17

How to create a new AMI from a snapshot and launch a

new VM

I took a factory-fresh AWS micro-instance and loaded a Drupal CMS onto it. Now my EC2
machine is running a customer service, but it is not enterprise-ready - it is not resilient. I
copy my original EC2 machine so I have a pair of identical servers. Next I will stick a load
balancer between them and the customer.
This process takes the original image, turns it off, takes a snapshot of the EBS volume,
makes a new AMI using this snapshot, then launches a new VM from my AMI. If you are
used to traditional IT and not AWS IT, you won't recognise those acronyms. They are part of
Amazon's new jargon.

AWS jargon
This article contains a fair amount of Amazon-specific acronyms and buzzwords, so here is
a mini-glossary as a reminder.

AMI (Amazon Machine Image): An EBS volume that contains an Operating System
and other bits required to launch instances. My new AMI doesn't have any optional
extras, so it is exactly like a physical computer's disk volume, with file system, kernel,
applications and everything else needed to boot up (to be pedantic, it's not exactly the
same, but most people won't notice any difference).

EBS (Elastic Block Storage): One of Amazon's cloud storage infrastructure services.
This is where the new AMI is stored. An EBS volume looks like a hard disk drive volume.
I could rent many EBS volumes, add files to them and mount them on my instance.

EC2 (Elastic Compute Cloud): The collective name for Amazon's cloud computing
services for customers.

instance: a complete running virtual machine. Every time you launch an AMI, you
get to choose its virtual hardware: maybe a Micro computer with the power of a net-top,
or perhaps a High Memory Quadruple Extra Large number-crunching monster with a
huge price tag, many processing cores and huge memory. I often call an instance a VM
or EC2 machine.

Root device: The EBS volume used to boot up my new instance.

Snapshot: A copy of your EBS volume (i.e., an image of the virtual hard disk drive).
AWS will make an AMI from your snapshot with some behind-the-scenes tinkering. If
you are used to VMware snapshots, you will find EC2 snapshots are not the same.

Examine the original EC2 machine.


My new EC2 machine must not be in the same area as the original VM, to make sure
maintenance doesn't affect both machines at the same time. My new instance must have
the same security group as the original VM to avoid unpleasant blockages.
1.

Open the AWS console.

2.

Find the availability zone and make a note of it.

3.

Note the security group.

Take a snapshot and make a new AMI


1.

Find the entry for your original VM. Click the Amazon EC2 tab | set your Region in
the drop-down list | Instances link in left navbar.

2.

Right click (or ctrl-click if you live in the pastel world of Mac OSX) the instance name.
The Instance Management context menu appears.

3.

Select Create Image (EBS AMI). A Create image window opens. (See Figure A
below.)

4.

Enter a name and description. This is for your use, not Amazon's.

5.

Click the Create This Image button. A confirmation message appears. Behind the
scenes the original EC2 machine is switched off, the EBS volume is copied to a
snapshot, and the EC2 machine is switched on again.

6.

Close the window. The list of images looks disappointingly unchanged - only the
original image is listed.

7.

Press the refresh button. The status check shows a warning about your original EC2
machine because the Instance Reachability Check fails.

8.

Wait a couple minutes, try again and your original EC2 machine is back to normal.

9.

View your original volume, new snapshot, and new AMI. Click Volumes, Snapshots
and AMIs links in the left navbar.

Figure A

AWS assigns unique identifiers for pretty much everything: your new AMI is labelled with an
identifier along the lines of ami-12345678 and the snapshot gets snap-12345678.

Launch a new instance


The AWS hypervisor takes a copy of the AMI template and adds secret sauce to turn it into
a running VM. The secret sauce contains host name, MAC address, IP addresses, billing
items and firewall rules.
1.

Find your new AMI. AMIs link in left navbar.

2.

Tick the checkbox. A description of the AMI appears in the lower pane.

3.

Click the Launch button. The Request Instances Wizard opens.

4.

Follow the wizard.

5.

The INSTANCE DETAILS boxes come first. Change the availability zone to
somewhere away from the original instance. Hit the continue button at the bottom of
the window. Enter a name like "second web server" or "cms02".

I chose my existing keypair in the CREATE KEY PAIR box. I can SSH to both
boxes with the same credentials.

I chose the same security group in the CONFIGURE FIREWALL box.

I hit the Launch button in the REVIEW box.

If you want more practice, terminate the instance and restart it - that's fine. Use the
new AMI image to launch another one. Repetition is good for learning.

Figure B

My Instances (click to enlarge)

If you were only running one free instance before, you are now being billed for renting the
second instance.

Figure C

The bill (click to enlarge)

Clean up
If you aren't going to load balance the pair of EC2 machines immediately, there's no point
hanging onto your work. It's easy to get to this point again.

Terminate the second VM.

De-register the AMI.

Delete the snapshot.

Close the AWS console.

How to restore EC2 Instance from Snapshot


http://blog.ecloudgate.com/how-to-restore-ec2-instance-from-snapshot/

To restore EC2 Instances from the snapshot(s) in the same or different AWS region follow these steps:
1.

Create a new EC2 Instances with parameters similar to the instance from which the snapshot(s) was
taken. If possible, the best practice would be to take an AMI of the existing EC2 and create a new
instance based on that AMI. The new instance can be created in any AWS region.

2.

Identify the snapshot that was taken from the root (C: drive) EBS volume
o

To identify root snapshot go to the AWS Management Console

Under EC2 section, click Instances

Select the source instance

In the Description section, click Root device type

Copy or Note EBS ID

Go to Snapshots section

In the Search field type or paste the EBS ID

On the list you should see the snapshots created from the root volume

3.

If the new instance will be launched in different AWS region, copy the root snapshot to destination
region, otherwise skip this step.
o

To copy a snapshot to a different region go to the AWS Management Console

Under EC2 section go to Snapshots and select the root snapshot

From the menu, select Copy

Choose the destination region and click Copy

4.

Stop the new EC2 Instance

5.

Detach the root volume from the Instance

6.

To identify root volume follow steps [a-d] from #2

Go to volumes

Type the volume ID in Search Volumes field

Check the root volume on the list

From Action select Force Detach Volume

Create a new volume based on the snapshot identified in #2

7.

Go to snapshots

Find the new snapshot

From Actions select Create Volume

Select appropriate type of Volume (Standard or IOPS)

You can enter the bigger size if needed

Availability zone must be the same as the one where a new EC2 instance was launched in

Click Create

Attach the new volume


o

Go to volumes

Select the volume that was created in #6

From Actions select Attach volume

In Instance field select the instance created in #1

In Device field type /dev/sda1

Click Attach

Start Instance

Here is much shorter version to achieve the same task using Elastic Cloud Gate console:
1.

Under the EC2 section, expend volumes under the instance from which the root snapshot was taken
from. The root volume will be shown in bold.

2.

From the menu select snapshots.

3.

In the new window from the menu select Create EC2 Instance.

4.

Set the configuration of the new EC2 Instance as well as what AMI option should be used as the base
for the new EC2 Instance.

5.

Click Launch.

ec2, restore insatnce from snapshot, snapshot

How to create and maintain RDS backups


http://blog.ecloudgate.com/how-to-create-and-maintain-rds-backups/

Using Amazon AWS Management Console you can create two types of RDS snapshots:

Automated Backup

DB Snapshot

Automated backup is the backup executed based on the daily schedule that enables point-in-time recovery of your
DB Instance.
DB Snapshot enables you to back up your DB Instance in a known state. The backup is executed manually from
AWS console.
The Automated backup can be setup when the new RDS DB Instance is launched.
To do this, under Management Options section check Enable Automatic Backup.
In addition you can specify the following:

Retention Period, which defines from how many days you want to keep your RDS backups. The value
can range from 0 (for no backup retention) to a maximum of 35 days.

Backup Window is the user-defined period of time during which your DB Instance is backed up. If you
dont have preference you can simply check No Preference.

You can modify these options after DB Instance was already launched.
To do this, under Instances select instance and from the Instance Actions select Modify.

To take DB Snapshot manually:


1.

Select DB Instance and from Instance Actions menu select Take DB Snapshot

2.

Type Snapshot Name and click Yes, Take Snapshot

As we mentioned above, AWS allows maximum of 35 days for backup period.


If you need to keep backup from more than 35 days or need more advanced scheduler with more flexibility in
execution time as well as retention period, here are the steps of how you can achieve it using Elastic Cloud Gate
console:
1.

Go to RDS section and from the menu select Schedule

2.

In the upper section of the RDS Scheduler, chose how frequently you want to create DB Snapshot
Occurrence:
o

Hourly The snapshot will be taken every given number of hours. In addition you can
specify start and end time. For instance, if you want to take a snapshot every 2 hours
between 8AM and 7PM, the setup would look like this:

If you skip the start and end time, the snapshot will be taken every given number of hours
around the clock.
o

Daily DB Snapshot will be taken every selected day and time. For instance, to take a
snapshot every Monday, Wednesday and Friday at 9PM, the setup would look like this:

Monthly DB Snapshot will be taken every given day of the month at given time. For
example, to take a snapshot every 3rd day of the month at 8AM, the setup would look like
this:

You can setup multiple schedulers for the same RDS instance and mix different frequencies if
needed. For instance, to take a snapshot every hour from 9AM to 5PM and another one daily at
11PM.

3.

In the next section you can change the following settings:


o

Description the description of the DB snapshot.

Copy Snapshot to Different Region when checked, this option will copy the new DB
Snapshot to the selected AWS region. You can select multiple destination regions. DB
Snapshot will be copied to all AWS regions simultaneously.

Amazon AWS allows to keep only up to 50 manual snapshots. So, when you use our scheduler after a while you
might get an error cannot create more than 50 manual snapshots. To prevent this, you can schedule retention of the
old DB Snapshots.
To schedule Maintenance (retention period) of the old DB Snapshots:
1.

There are two options allowing to define which DB Snapshot should not be deleted:
o

Keep All From Last this option will keep all DB Snapshots created within the last x
periods (period can be selected as hours, days, weeks, months or years). For example, if
you want to keep all DN Snapshots created within the last 45 days, you setup would look
like this:

Keep One Per Period From Last this option will only keep the DB Snapshots created last
in the given period (i.e. hours, days, weeks, months or years). For instance, if you want to
keep one DB Snapshot per week from the last 8 weeks, the setup would look like this:

All DB Snapshots which do not match scheduler will be deleted.


2.

You can setup advanced maintenance plan for RDS by creating multiple schedules. For example, to
setup maintenance that would keep all DB Snapshots from the last 7 days, 1 DB Snapshot per week
from the last 4 weeks and 1 DB Snapshot per month from the last 4 months, the setup would look like
this:

To see other features offered by Elastic Cloud Gate related to RDS visit: https://www.ecloudgate.com/Tour/RDS

Potrebbero piacerti anche