如何使用 Cloudformation 更改 LaunchConfig 设置?

How can I change LaunchConfig settings with Cloudformation?

我有一个 AutoScale 和一个我之前创建的 LaunchConfig。我想在 LaunchConfig 中用 Cloudformation 替换 AMI ID。我该怎么做?

请问有没有样板可供我参考?

您可以找到简单的例子:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-launchconfig.html#aws-properties-as-launchconfig--examples

   ---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
  LatestAmiId:
    Description: Region specific image from the Parameter Store
    Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
    Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
  InstanceType:
    Description: Amazon EC2 instance type for the instances
    Type: String
    AllowedValues:
      - t3.micro
      - t3.small
      - t3.medium
    Default: t3.micro
Resources:
  myLaunchConfig: 
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: !Ref LatestAmiId
      SecurityGroups: 
        - Ref: "myEC2SecurityGroup"
      InstanceType: 
        Ref: "InstanceType"
      BlockDeviceMappings: 
        - DeviceName: /dev/sda1
          Ebs: 
            VolumeSize: 30
            VolumeType: "gp3"
        - DeviceName: /dev/sdm
          Ebs: 
            VolumeSize: 100
            DeleteOnTermination: "false"