Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AWS CDK (Typescript) How run AutoScalingGroup without use deprecated launch configurations?

I am using AWS CDK (Typescript version) to create a AutoScalingGroup:

const asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
  instanceType: ec2.InstanceType.of(
    ec2.InstanceClass.T2,
    ec2.InstanceSize.MICRO
  ),
  machineImage: ami,
  minCapacity: 2,
  maxCapacity: 5,
  securityGroup: securityGroup,
  vpc,
  role: role,
});

Everything works and I have 2 instances:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However, I was extremely surprised that CDK uses Launch configurations when it marks this method as deprecated:

enter image description here

How can I solve this problem is using the AutoScalingGroup?

enter image description here

If possible, can you give me an example code?

Best Regards

>Solution :

The AutoScalingGroup construct accepts to pass the launchTemplate parameter.

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.AutoScalingGroup.html#launchtemplate

You need to pass there the object of the ILaunchTemplate interface described here: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ILaunchTemplate.html

Without creating a launch template explicitly, you’ll always use the old launch configurations. My guess is that AWS doesn’t make new templates default for the backward compatibility of CDK.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading