fbpx

You have the option to configure Block Device Mapping settings for an Elastigroup to provision and handle volumes for your instances. Block device mapping can be used to configure the root volume of the instance.as well as data volumes. Elastigroup configured Block Device mappings will override AMI Block device mappings per device name.

For additional information, you can check out the AWS documentation for Block Device Mappings

Block Device Mappings settings can be added or managed via API while creating a group or as an update to a group, or via the UI at the last step of the Creation Wizard – in the Review Tab.

How to implement?

Navigate to the relevant Elastigroup and open the creation wizard to enter the Review Tab via Actions –> Edit configuration –> Review Tab –> Edit mode

 

Add the  Block device mappings JSON block in the “launchSpecification” object ( compute.launchSpecification.blockDeviceMappings ):

Example blockDeviceMappings object overriding the settings for 3 drives: /dev/sdf , /dev/sdm , /dev/sda1

Note: in this case, the root volume is sda1, the root volume can also be xvda.
"blockDeviceMappings": [
  {
    "deviceName": "/dev/sdm",
    "ebs": {
      "deleteOnTermination": true,
      "volumeSize": 80,
      "volumeType": "gp2"
    }
  },
 {
    "deviceName": "/dev/sdf",
    "ebs": {
      "deleteOnTermination": true,
      "snapshotId": "snap-09e8dccc6a7512345",
      "volumeSize": 500,
      "volumeType": "gp2"
    }
  },
  {
    "deviceName": "/dev/sda1",
    "ebs": {
      "deleteOnTermination": true,
      "volumeSize": 48,
      "volumeType": "gp2"
    }
  }
]

Alternatively, you can use the update API with the following Body:

{
  "group": {
    "compute": {
      "launchSpecification": {
        "blockDeviceMappings": [
          {
            "deviceName": "/dev/sdm",
            "ebs": {
              "deleteOnTermination": true,
              "volumeSize": 80,
              "volumeType": "gp2"
            }
          },
          {
            "deviceName": "/dev/sdf",
            "ebs": {
              "deleteOnTermination": true,
              "snapshotId": "snap-09e8dccc6a7512345",
              "volumeSize": 500,
              "volumeType": "gp2"
            }
          },
          {
            "deviceName": "/dev/sda1",
            "ebs": {
              "deleteOnTermination": true,
              "volumeSize": 24,
              "volumeType": "gp2"
            }
          }
        ]
      }
    }
  }
}
Use Case #1 – Deploy a group with an existing volume in case of a spot termination/recycle

BDM allows you create a new instance which is based on an existing Snapshot. While using the method above, you can specify an existing snapshotId so that the volume will be created based on the provided Snapshot.

Use Case #2 – Modify the type/size of a Device

With BDM you can manage the volume type/size dynamically by modifying the size/type according to the current need.

 
{
  "deviceName": "/dev/sda1",
  "ebs": {
    "deleteOnTermination": "true",
    "volumeSize": 24, <---- Setting the volume size
    "volumeType": "gp2" <---- Setting the Volume type
  }
}
How to remove BDM

In case you have a Block Device Mapping setting in your Elastigroup, and you would like to disable it, go to the relevant ElastiGroup ID –> Actions –> Edit configuration –> Review. Click the “Edit Mode” toggle, and now simply replace the values under the "blockDeviceMappings" key with null like so:

"blockDeviceMappings": null,

Click Update to apply the changes, and optionally Roll your group.

The implementation is the same if you are using the Update API.