Discussion:
AWS: create server from ebs snapshot
David Kerr
2012-12-31 19:05:30 UTC
Permalink
Howdy!

I'm hoping someone can give me an example of how to create an AWS instance
from a snapshot. (basically, I want to clone a server)

I'm able to get the volumes snapshotted ok
box = $ec2.servers.get(x.resource_id)
box.volumes.all.each { |x|
snapshot = x.snapshot
// do stuff
}

so now that i've got these snapshots, I'm not entirely sure how to create
the new instance with them, i could create the instance
and add the volumes after the fact, but I'm looking to replace the root
partition, so it seems like i'd want to replace them on creation.
For a while i thought block_device_mapping was what I wanted, but there
doesn't seem to be a snapshot-id for that.

Any help would be awesome,

Thanks
Frederick Cheung
2012-12-31 19:34:25 UTC
Permalink
Post by David Kerr
Howdy!
I'm hoping someone can give me an example of how to create an AWS instance from a snapshot. (basically, I want to clone a server)
I'm able to get the volumes snapshotted ok
box = $ec2.servers.get(x.resource_id)
box.volumes.all.each { |x|
snapshot = x.snapshot
// do stuff
}
so now that i've got these snapshots, I'm not entirely sure how to create the new instance with them, i could create the instance
and add the volumes after the fact, but I'm looking to replace the root partition, so it seems like i'd want to replace them on creation.
For a while i thought block_device_mapping was what I wanted, but there doesn't seem to be a snapshot-id for that.
You can set a snapshot id with a block device mapping - i've got code that looks like this (creating spot instances, but the basic principle is the same

compute.request_spot_instances DeploymentConfig['ami_64bit'], 'm2.xlarge', 0.60, {
'InstanceCount' => 1,
'LaunchSpecification.SecurityGroup' => 'compute_node',
'Type' => 'one-time',
'LaunchSpecification.BlockDeviceMapping' =>
[{'DeviceName' => '/dev/sdg',
'Ebs.SnapshotId' => DeploymentConfig['snapshot_id'],
'Ebs.VolumeSize' => 3,
'Ebs.DeleteOnTermination' => true}]
}

However I don't think you can do this with the boot volume - I've always built custom AMIs when I want to do that (the AMI is itself backed by a snapshot), although to be fair I've never tried

Fred
David Kerr
2012-12-31 19:36:32 UTC
Permalink
Post by David Kerr
Post by David Kerr
Howdy!
I'm hoping someone can give me an example of how to create an AWS
instance from a snapshot. (basically, I want to clone a server)
Post by David Kerr
I'm able to get the volumes snapshotted ok
box = $ec2.servers.get(x.resource_id)
box.volumes.all.each { |x|
snapshot = x.snapshot
// do stuff
}
so now that i've got these snapshots, I'm not entirely sure how to
create the new instance with them, i could create the instance
Post by David Kerr
and add the volumes after the fact, but I'm looking to replace the root
partition, so it seems like i'd want to replace them on creation.
Post by David Kerr
For a while i thought block_device_mapping was what I wanted, but there
doesn't seem to be a snapshot-id for that.
You can set a snapshot id with a block device mapping - i've got code that
looks like this (creating spot instances, but the basic principle is the
same
compute.request_spot_instances DeploymentConfig['ami_64bit'], 'm2.xlarge', 0.60, {
'InstanceCount' => 1,
'LaunchSpecification.SecurityGroup' => 'compute_node',
'Type' => 'one-time',
'LaunchSpecification.BlockDeviceMapping' =>
[{'DeviceName' => '/dev/sdg',
'Ebs.SnapshotId' => DeploymentConfig['snapshot_id'],
'Ebs.VolumeSize' => 3,
'Ebs.DeleteOnTermination' => true}]
}
However I don't think you can do this with the boot volume - I've always
built custom AMIs when I want to do that (the AMI is itself backed by a
snapshot), although to be fair I've never tried
Fred
I just found the section for creating an AMI image and I agree that seems
like the more sane way to go. Thanks!

Dave

Loading...