首页 > 解决方案 > 如何在使用 aws cdk 创建自动缩放组时选择固定的 aws linux 映像机器?

问题描述

我正在使用以下代码使用 aws cdk 创建一个自动缩放组:

const mySecurityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {...});
new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
  machineImage: new ec2.AmazonLinuxImage(),
  securityGroup: mySecurityGroup,
});

我面临的问题是,在每次代码管道部署之后,自动缩放组都被替换了。发生这种情况是因为每次部署后,AmazonLinuxImage 都会更新到最新版本,这将更改自动扩展组的启动配置。另一方面,查看文档,您可以找到以下内容:

NOTE: The Amazon Linux images selected will be cached in your cdk.json, so that your AutoScalingGroups don't automatically change out from under you when you're making unrelated changes. To update to the latest version of Amazon Linux, remove the cache entry from the context section of your cdk.json.

我在文档中没有找到有关如何应用上述内容的任何示例。我需要选择一个固定的linux镜像机器,以防止在每次部署后更新自动缩放组的启动配置。

标签: amazon-web-servicesaws-cdkaws-auto-scaling

解决方案


推荐阅读