如何在 aws 堆栈中添加多个 ec2 实例

how to add multiple ec2 instances inside aws stack

我想通过门户或通过云形成创建 AWS 堆栈。但我想在一个堆栈中添加多个 EC2 实例。我没有找到足够的例子。我怎样才能找到一个?

只需在您的 CloudFormation 模板中添加更多 AWS::EC2::Instance resource

例如:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Ec2 block device mapping",
  "Resources": {
    "MyEC2Instance1": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "ImageId": "ami-79fd7eee",
        "KeyName": "testkey1",
        "BlockDeviceMappings": [
          {
            "DeviceName": "/dev/sdm",
            "Ebs": {
              "VolumeType": "io1",
              "Iops": "200",
              "DeleteOnTermination": "false",
              "VolumeSize": "20"
            }
          },
          {
            "DeviceName": "/dev/sdk",
            "NoDevice": {
            }
          }
        ]
      }
    },
    "MyEC2Instance2": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "ImageId": "ami-79fd7eee",
        "KeyName": "testkey2",
        "BlockDeviceMappings": [
          {
            "DeviceName": "/dev/sdm",
            "Ebs": {
              "VolumeType": "io1",
              "Iops": "200",
              "DeleteOnTermination": "false",
              "VolumeSize": "20"
            }
          },
          {
            "DeviceName": "/dev/sdk",
            "NoDevice": {
            }
          }
        ]
      }
    }
  }
}