how to add multiple ec2 instances inside aws stack

痞子三分冷 提交于 2019-12-13 09:51:56

问题


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:


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": {
            }
          }
        ]
      }
    }
  }
}


来源:https://stackoverflow.com/questions/46525053/how-to-add-multiple-ec2-instances-inside-aws-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!