1

I've been using logic to specify disk size when launching new instances. However, the problem is that it requires knowing DeviceName which depends on instance type. It's usually /dev/sda1 but on p3dn.24xlarge instances, the default disk comes up /dev/xvda device instead, so my instance ends up with 2 volumes:

 /dev/xvda          8        gp2          vol-06402d0bcb07d3b96 
 /dev/sda1        500        gp2          vol-0e2593027d73fbc52 

I could hardwire p3dn as special case but not sure if this is likely to break in the future, any suggestions of a better way of doing this?

Code

      assert disk_size > 0
      ebs = {
        'VolumeSize': disk_size,
        'VolumeType': 'gp2',
      }

      args['BlockDeviceMappings'] = [{
        'DeviceName': '/dev/sda1',
        'Ebs': ebs
      }]

      instances = ec2.create_instances(**args)

MyStackRunnethOver
  • 4,872
  • 2
  • 28
  • 42
Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197
  • 1
    Possibly relevant: [this question](https://stackoverflow.com/questions/32215987/how-to-specify-root-volume-size-of-core-os-ec2-instance-using-boto3) and from an answer comment: "To get the device name consistently with boto3: `imgs = list(ec2.images.filter(ImageIds=['my-image-id'])); device_name = imgs[0].root_device_name`" – MyStackRunnethOver Jun 24 '19 at 23:26

1 Answers1

0
  image = list(ec2.images.filter(ImageIds=['my-image-id']))[0]
  args['BlockDeviceMappings'] = [{
    'DeviceName': image.root_device_name,
    'Ebs': ebs
  }]
Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197