使用AWS-CDK,Python将块设备映射添加到EC2

时间:2020-09-17 20:14:46

标签: amazon-web-services aws-cdk

为ebs卷添加2个块设备映射时出现错误。我正在使用aws-cdk,python。

这是代码

    from aws_cdk import core
    from aws_cdk import aws_ec2 as _ec2

    #Webserver 01
    webserver = _ec2.Instance(
        self,
        "webserver01Id",
        instance_type = _ec2.InstanceType(instance_type_identifier="t2.micro"),
        instance_name = "webserver001",
        machine_image = _amzn_linux_ami,            
        vpc=vpc,
        vpc_subnets = _ec2.SubnetSelection(subnet_type=_ec2.SubnetType.PUBLIC),
        user_data = _ec2.UserData.custom(_user_data),
        block_devices= {"block_device_mappings": [
            {"device_name ": '/dev/sda1', "volume": _ec2.BlockDeviceVolume.ebs(50)}, 
            {"device_name": '/dev/sdm', "volume": _ec2.BlockDeviceVolume.ebs(100)}
            ]
        } 
    )

这是我遇到的错误。

jsii.errors.JSIIError:预期的数组类型,得到了{“ $ jsii.map”:{“ block_device_mappings”:[{“ $ jsii.map”:{“ device_name”:“ / dev / sda1”,“ volume “:{” $ jsii.byref“:” @ aws-cdk/aws-ec2.BlockDeviceVolume@10012“}}},{” $ jsii.map“:{” device_name“:” / dev / sdm“,” volume “:{” $ jsii.byref“:” @ aws-cdk/aws-ec2.BlockDeviceVolume@10013“}}}]}} 子流程退出,错误1

1 个答案:

答案 0 :(得分:0)

用于aws_ec2.Instance类的CDK API 1.63.0的最新版本规定block_devices应该是aws_ec2.BlockDevice实例link here的列表,而不是{{1 }}。