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

huangapple go评论53阅读模式
英文:

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

问题

我正在使用AWS CDKTypescript版本创建一个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:

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

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

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

How can I solve this problem is using the AutoScalingGroup?

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

If possible, can you give me an example code?

Best Regards

答案1

得分: 1

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.

自动扩展组构造函数接受传递 launchTemplate 参数。

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.AutoScalingGroup.html#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.

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.

huangapple
  • 本文由 发表于 2023年3月1日 16:12:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601019.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定