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:
However, I was extremely surprised that CDK uses Launch configurations when it marks this method as deprecated:
How can I solve this problem is using the AutoScalingGroup?
If possible, can you give me an example code?
Best Regards
The AutoScalingGroup construct accepts to pass the launchTemplate
parameter.
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.