0

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?

Community
  • 1
  • 1
I Z
  • 5,719
  • 19
  • 53
  • 100

1 Answers1

0

There may be other issues but one problem I see is the value you are providing for iops in the block device mapping. That value must be between 100-4000 (see API docs).

garnaat
  • 44,310
  • 7
  • 123
  • 103
  • Bingo! Changed the value to 101 and it worked (don't like boundary values :)). What's strange is that I think you can set iops values to lower than 100 through the AWS console. – I Z Aug 21 '14 at 13:54
  • It's also strange that you didn't get some sort of error. It seems like that could have been detected at the time the ``RunInstances`` request was received. – garnaat Aug 21 '14 at 14:35