Aws-cdk: create AutoScalingGroup fail with block_devices

Created on 20 Jan 2020  路  6Comments  路  Source: aws/aws-cdk

Create AutoScalingGroup fail with block_devices definition in cdk deploy (python)

Cloudformation fail on error

Cannot specify both EBS volume and no-device for block devices. (Service: AmazonAutoScaling; Status Code: 400; Error Code: ValidationError;

Python code

autoscaling.AutoScalingGroup(self, "ASG",
    vpc=vpc,
    instance_type=ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
    machine_image=ec2.AmazonLinuxImage(),
    block_devices=[autoscaling.BlockDevice(device_name="/dev/sdb", volume=autoscaling.BlockDeviceVolume.ebs(20))]
)

CloudFormation Output

        "BlockDeviceMappings": [
          {
            "DeviceName": "/dev/xvda",
            "Ebs": {
              "DeleteOnTermination": true,
              "VolumeSize": 12,
              "VolumeType": "gp2"
            },
            "NoDevice": false
          }
        ],

The older version cdk hasn't this issue with same cdk coding, it didn't output "NoDevice" key.

Environment

[email protected]


This is :bug: Bug Report

@aws-cdaws-autoscaling bug needs-triage p1

Most helpful comment

I found a workaround on https://gitter.im/awslabs/aws-cdk?at=5e1f66b58b5d766da1aea4d4
Leave BlockDevices undefined in ASG construct and add a property override to the launch configuration like this:

        my_asg = autoscaling.AutoScalingGroup(
            self,
            "MyASG",
            vpc=my_vpc,
            instance_type=ec2.InstanceType.of(
                ec2.InstanceClass.BURSTABLE3_AMD,
                ec2.InstanceSize.LARGE
            ),
            machine_image=ec2.AmazonLinuxImage(
                generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2),
            max_capacity=1,
            min_capacity=1,
            user_data=my_user_data,
        )

        config = my_asg.node.find_child('LaunchConfig')
        config.add_property_override(
            property_path="BlockDeviceMappings",
            value=[{'DeviceName': '/dev/xvda', 'Ebs': {'VolumeSize': 100}}]
        )

You can set other properties for the Ebs e.g. {'VolumeSize': 100, 'Encrypted': True,
'DeleteOnTermination': True, 'VolumeType': 'gp2'} but for my use case I didn't need to. You can also add multiple devices.

All 6 comments

Agree, i am also facing similar error, just upgraded from [email protected] to [email protected]

I have the same issue using version 1.21.1 with following code.

const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ecsAutoscalingGroup', {
            vpc: props.vpc,
            instanceType: new ec2.InstanceType('t3.xlarge'),
            machineImage: ecs.EcsOptimizedImage.amazonLinux2(),
            blockDevices: [{
                deviceName: '/dev/xvda',
                volume: ec2.BlockDeviceVolume.ebs(128)
            }],
            minCapacity: 1,
            maxCapacity: 5
        })
        cluster.addAutoScalingGroup(autoScalingGroup)

I have the same problem. Has anyone worked out exactly which version it broke on? I downgraded to CDK 1.19.0 and aws-cdk.aws-autoscaling==1.19.0 and still get this error.

I found a workaround on https://gitter.im/awslabs/aws-cdk?at=5e1f66b58b5d766da1aea4d4
Leave BlockDevices undefined in ASG construct and add a property override to the launch configuration like this:

        my_asg = autoscaling.AutoScalingGroup(
            self,
            "MyASG",
            vpc=my_vpc,
            instance_type=ec2.InstanceType.of(
                ec2.InstanceClass.BURSTABLE3_AMD,
                ec2.InstanceSize.LARGE
            ),
            machine_image=ec2.AmazonLinuxImage(
                generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2),
            max_capacity=1,
            min_capacity=1,
            user_data=my_user_data,
        )

        config = my_asg.node.find_child('LaunchConfig')
        config.add_property_override(
            property_path="BlockDeviceMappings",
            value=[{'DeviceName': '/dev/xvda', 'Ebs': {'VolumeSize': 100}}]
        )

You can set other properties for the Ebs e.g. {'VolumeSize': 100, 'Encrypted': True,
'DeleteOnTermination': True, 'VolumeType': 'gp2'} but for my use case I didn't need to. You can also add multiple devices.

I found a workaround on https://gitter.im/awslabs/aws-cdk?at=5e1f66b58b5d766da1aea4d4
Leave BlockDevices undefined in ASG construct and add a property override to the launch configuration like this:

        my_asg = autoscaling.AutoScalingGroup(
            self,
            "MyASG",
            vpc=my_vpc,
            instance_type=ec2.InstanceType.of(
                ec2.InstanceClass.BURSTABLE3_AMD,
                ec2.InstanceSize.LARGE
            ),
            machine_image=ec2.AmazonLinuxImage(
                generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2),
            max_capacity=1,
            min_capacity=1,
            user_data=my_user_data,
        )

        config = my_asg.node.find_child('LaunchConfig')
        config.add_property_override(
            property_path="BlockDeviceMappings",
            value=[{'DeviceName': '/dev/xvda', 'Ebs': {'VolumeSize': 100}}]
        )

You can set other properties for the Ebs e.g. {'VolumeSize': 100, 'Encrypted': True,
'DeleteOnTermination': True, 'VolumeType': 'gp2'} but for my use case I didn't need to. You can also add multiple devices.

Good find. Had used this approach as a temporary workaround until the fix

It seems:

NoDevice: true
NoDevice: false

Mean the same thing--the value of the boolean is not honored, just the presence of the key.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artyom-melnikov picture artyom-melnikov  路  3Comments

eladb picture eladb  路  3Comments

ababra picture ababra  路  3Comments

nzspambot picture nzspambot  路  3Comments

PaulMaddox picture PaulMaddox  路  3Comments