When creating an instance in AWS the volume root size defaults to 8GB, I am trying to create an instance using boto3 but with a different default size, for example 300GB, I am currently trying something like this without success:
block_device_mappings = []
block_device_mappings.append({
'DeviceName': '/dev/sda1',
'Ebs': {
'VolumeSize': 300,
'DeleteOnTermination': True,
'VolumeType': 'gp2'
}
Any idea of how to achieve this?
Most likely what is happening is that you're using an AMI that uses
/dev/xvda
instead of/dev/sda1
for its root volume.AMIs these days support one of two types of virtualization, paravirtual (PV) or hardware virtualized (HVM), and PV images support
/dev/sda1
for the root device name, whereas HVM images can specify eitherdev/xvda
or/dev/sda1
(more from AWS Documentation).You can add in an image check to determine what the AMI you're using sets its root volume to, and then use that information for your calls to
create_images
.Here's a code snippet that makes a call out to
describe_images
, retrieves information about itsRootDeviceName
, and then uses that to configure the block device mapping.For reference, the call to
describe_images
returns adict
that looks like this: