how to add multiple ec2 instances inside aws stack

2019-09-19 15:24发布

I want to create an AWS stack through portal or through cloud formation. But I want to add multiple EC2 instances in one single stack. I am not finding enough examples. How can I find one ?

1条回答
等我变得足够好
2楼-- · 2019-09-19 16:00

Just add more AWS::EC2::Instance resource into your CloudFormation template.

For example:

{
  "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": {
            }
          }
        ]
      }
    }
  }
}
查看更多
登录 后发表回答