I cannot figure out from documentation and source code how to define size of the root device.
You can specify N additional block devices using BlockDeviceMappings section where you can declare their sizes. But there is no way to set size of the root volume. So it always create an instance with root volume of size 8GB which is the default value.
AWS EC2 Root Device Volume. When an EC2 instance is launched from an AMI, the root device volume contains the image used to boot the instance—mainly the operating system, all the configured services, and applications.
Expand the EBS root volume of EC2 Linux running on a current generation instance without detaching and reattaching the volume by using the Amazon EBS Elastic Volumes feature. To expand the EBS root volume of EC2 Linux running on a previous generation instance, you must detach and then reattach the volume.
Ran into this issue myself today, probably to late for the original poster, but in case anyone else stumbles across this question later I did the following:
import boto3
ec2 = boto3.resource('ec2',
region_name='eu-west-1',
aws_access_key_id='my-key',
aws_secret_access_key='my-secret')
instance = ec2.create_instances(ImageId='my-image-id',
BlockDeviceMappings=[{"DeviceName": "/dev/xvda","Ebs" : { "VolumeSize" : 50 }}])
The above has been truncated (you'll need to pass more arguments to create_instances for other values, InstanceType etc.) but essentially pass the root device (/dev/xvda in this case) in as part of the BlockDeviceMappings value with the desired volume size (50GB in the above example).
Same as Steve Jeffereies has mentioned, naming the DeviceName is the key. I was able to use /dev/sda1 which you would usually see on AWS console. The following is a working example using magnetic,
BlockDeviceMappings=[
{
'DeviceName': '/dev/sda1',
'Ebs': {
'VolumeSize': 30,
'VolumeType': 'standard'
}
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With