英文:
AWS CDK (Typescript) How run AutoScalingGroup without use deprecated launch configurations?
问题
我正在使用AWS CDK(Typescript版本)创建一个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,
});
一切正常,我有2个实例:
[![进入图像描述][1]][1]
然而,让我非常惊讶的是,CDK在标记此方法为弃用时使用了Launch配置:
[![进入图像描述][2]][2]
我该如何解决使用AutoScalingGroup时出现的问题?
[![进入图像描述][3]][3]
如果可能的话,你能给我一个示例代码吗?
最好的问候
[1]: https://i.stack.imgur.com/zI8Ou.png
[2]: https://i.stack.imgur.com/h1YD4.png
[3]: https://i.stack.imgur.com/hZH1O.png
英文:
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
答案1
得分: 1
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.
自动扩展组构造函数接受传递 launchTemplate
参数。
您需要在此处传递 ILaunchTemplate 接口的对象,该接口在此处描述:https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ILaunchTemplate.html
如果没有显式创建启动模板,则始终将使用旧的启动配置。我猜测 AWS 之所以不将新模板设为默认值,是为了保证与 CDK 的向后兼容性。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论