在CDK中,如何在具有`mixedInstancesPolicy`配置的自动伸缩组中启用`associatePublicIpAddress`?

0

【以下的问题经过翻译处理】 我正在使用 AWS CDK 并尝试为使用了启动模板的自动伸缩组启用 associatePublicIpAddress 属性。

我的第一次尝试是设置 associatePublicIpAddress: true,但我收到了这个错误 (<https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-autoscaling/lib /auto-scaling-group.ts#L1526-L1528>)

//  首次尝试
new asg.AutoScalingGroup(this, 'ASG', {
  associatePublicIpAddress: true, // here
  minCapacity: 1,
  maxCapacity: 1,
  vpc,
  vpcSubnets: {
    subnetType: SubnetType.PUBLIC,
    onePerAz: true,
    availabilityZones: [availabilityZone],
  },
  mixedInstancesPolicy: {
    instancesDistribution: {
      spotMaxPrice: '1.00',
      onDemandPercentageAboveBaseCapacity: 0,
    },
    launchTemplate: new LaunchTemplate(this, 'LaunchTemplate', {
      securityGroup: this._securityGroup,
      role,
      instanceType
      machineImage,
      userData: UserData.forLinux(),
    }),
    launchTemplateOverrides: [
      {
        instanceType: InstanceType.of(
          InstanceClass.T4G,
          InstanceSize.NANO
        ),
      },
    ],
  },
  keyName,
})

// 错误信息

    if (props.associatePublicIpAddress) {
      throw new Error('Setting \'associatePublicIpAddress\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set');
    }

我的第二次尝试是不设置 associatePublicIpAddress 并查看它是否自动设置,因为自动伸缩组位于具有互联网网关的公共子网中。但实际上它仍然没有提供公网 IP 地址。

自动伸缩组是否支持同时配置mixedInstancesPolicyassociatePublicIpAddress

1 Antwort
0

【以下的回答经过翻译处理】 您正在为ASG设置associatePublicIpAddress,而正确的做法是将其设置在启动模板上或更改子网的默认行为“associatePublicIpAddress=true”。仅拥有IGW并不自动更改子网自动分配公网 IP 的设置,除了默认VPC中的默认子网外,其他子网不会自动分配公网 IP。

您链接的代码函数称为“verifyNoLaunchConfigPropIsGiven”,意味着这些属性是为启动配置(已被启动模板替换的较旧的功能)而设计的。

profile picture
EXPERTE
beantwortet vor 5 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen