Skip to content

Instantly share code, notes, and snippets.

@gingerlime
Last active April 16, 2016 16:07
Show Gist options
  • Save gingerlime/e24a57b6a5a3bf9edf123560599435b9 to your computer and use it in GitHub Desktop.
Save gingerlime/e24a57b6a5a3bf9edf123560599435b9 to your computer and use it in GitHub Desktop.
dev_map = boto.ec2.blockdevicemapping.BlockDeviceMapping()
block = boto.ec2.blockdevicemapping.EBSBlockDeviceType()
block.snapshot_id = snapshot.id
block.size = 40
block.volume_type = 'gp2'
dev_map[ROOT_DEV] = block
swap = boto.ec2.blockdevicemapping.BlockDeviceType()
swap.ephemeral_name = 'ephemeral0'
dev_map[SWAP_DEV] = swap
new_img = conn.register_image(name=SERVER,
description=SERVER,
architecture=ARCH,
virtualization_type=VIRT,
root_device_name=ROOT_DEV,
block_device_map=dev_map)
img = conn.get_image(new_img)
status = img.update()
while status == u'pending':
time.sleep(7)
status = img.update()
if status == u'available':
print 'image created'
else:
print "image status: %s" % status
return
server = conn.run_instances(img.id,
instance_type=INSTANCE_TYPE,
key_name=KEYPAIR,
placement=ZONE,
block_device_map=dev_map).instances[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment