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

后端 未结 4 2168
礼貌的吻别
礼貌的吻别 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:11

    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'
                    }
                }
            ]
        )
    

提交回复
热议问题