Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify root volume size of core-os ec2 instance using boto3?

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.

like image 756
lisak Avatar asked Aug 26 '15 00:08

lisak


People also ask

What is the root volume of the Amazon EC2 instance?

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.

How do I increase the root volume size in an EC2 instance in Linux?

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.


2 Answers

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).

like image 117
Steve Jefferies Avatar answered Sep 21 '22 13:09

Steve Jefferies


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'
        }
    }
]
like image 20
barryku Avatar answered Sep 19 '22 13:09

barryku