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

后端 未结 4 2066
礼貌的吻别
礼貌的吻别 2021-02-05 17:39

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

4条回答
  •  再見小時候
    2021-02-05 18:07

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

提交回复
热议问题