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 sectio
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'
}
}
]
Follow is minimal required fields that have to be set the size of the root device:
import boto3
ec2_resource = boto3.resource('ec2')
reservations = ec2_resource.create_instances(
ImageId= "ami-xyz",
MinCount=1,
MaxCount=1,
InstanceType='xyz',
KeyName='key-pair',
TagSpecifications=[
{
'ResourceType': 'instance',
'Tags': [{
'Key': 'Name',
'Value': 'xyz-machine'
}]
}
],
IamInstanceProfile={
'Name':'xyz-role'
},
BlockDeviceMappings=[
{
'DeviceName': '/dev/sda1',
'Ebs': {
'VolumeSize': 30,
'VolumeType': 'standard'
}
}
]
)
See Stackoverflow: How to launch EC2 instance with Boto, specifying size of EBS?
Also, here's a way to do it from the AWS Command-Line Interface (CLI):
aws ec2 run-instances --image-id ami-xxxxxxxx --instance-type m1.xlarge --block-device-mappings '{"DeviceName": "/dev/sda1","Ebs" : { "VolumeSize" : 50 }}'