Here's a block of code that is used to create an EC2 instance:
def create_instance(connection, name, instance_type, security_groups, ami, key, placement, cluster, optimized_ebs):
#NEW BLOCK BEGIN
dev_sda1 = boto.ec2.blockdevicemapping.EBSBlockDeviceType()
dev_sda1.size = 23 # size in Gigabytes
dev_sda1.volume_type = 'io1'
dev_sda1.iops = 44
bdm = boto.ec2.blockdevicemapping.BlockDeviceMapping()
bdm['/dev/sda1'] = dev_sda1
#NEW BLOCK END
res = connection.run_instances(
ami,
key_name=key,
instance_type=instance_type,
security_groups=security_groups,
placement=placement,
ebs_optimized=optimized_ebs,
block_device_map=bdm)
inst = res.instances[0]
time.sleep(30)
inst.update()
connection.create_tags([inst.id], {'Name': '%s-%s' % (cluster, name),'Cluster': cluster})
Before the #NEW BLOCK
code block was added it all worked. After create_instance
was called, I would check the state of the new instance and it would be 'running'
.
I added the block to create the instance with the volume of type 'IO1' instead of the default (following the accepted answer here). I do not get any exceptions or other errors here but when I check the instance state later I get 'terminated'
. What am I doing wrong?