question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

create AutoScalingGroup fail with block_devices

See original GitHub issue

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

aws-cdk@1.21.1


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sheridansmallcommented, Jan 21, 2020

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.

1reaction
fwerkmeistercommented, Jan 21, 2020

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

EC2 instance launch failures - Amazon EC2 Auto Scaling
This page provides information about your EC2 instances that fail to launch, potential causes, and the steps you can take to resolve the...
Read more >
How do I troubleshoot scaling issues with my Amazon EC2 ...
... 0:26For more details see the Knowledge Center article with this video: https://aws.amazon.com/premiumsupport/knowledge-center/ auto...
Read more >
AWS launch configuration CLI Block Devices not included
I am attempting to automate the creation process of launch configurations for my auto scaling group in aws. I am able to successfully...
Read more >
can't create AutoScaling group from launch template
I created my launch template from an existing EC2 instance. When I try to create an AutoScaling group from the template, I get...
Read more >
Review - Chapter 5 AWS Flashcards | Quizlet
Identifying a key pair, security group, and a block device mapping are optional elements for an Auto Scaling launch configuration. 5. You are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found