为 EC2 机队实例分配弹性 IP 地址

为 EC2 机队实例分配弹性 IP 地址

我正在使用 cloudformation 中的 EC2 Fleet 服务创建多个 EC2 实例,我想为 EC2 Fleet 中新创建的实例分配弹性 IP 地址,

以下是我的模板,

有人可以帮忙吗?提前谢谢您。

   "AWSTemplateFormatVersion":"2010-09-09",
   "Description":"Template to Create OnDemand EC2 Fleet using LaunchTemplate",
   "Resources":{
      "EC2FleetLaunchTemplate":{
         "Type":"AWS::EC2::LaunchTemplate",
         "Properties":{
            "LaunchTemplateName":"MainEC2Fleet-LaunchTemplate",
            "LaunchTemplateData":{
               "ImageId":{
                  "Fn::FindInMap":[
                     "RegionMap",
                     {
                        "Ref":"AWS::Region"
                     },
                     "AMI"
                  ]
               },
               "InstanceType":"t2.micro",
               "KeyName":{
                  "Ref":"SSHKeyName"
               },
               "NetworkInterfaces":[
                  {
                     "DeviceIndex":"0",
                     "AssociatePublicIpAddress":true,
                     "DeleteOnTermination":true,
                     "SubnetId":{
                        "Ref":"Subnet"
                     },
                     "Groups":[
                        {
                           "Ref":"InstanceSecurityGroup"
                        }
                     ]
                  }
               ]
            }
         }
      },
      "LaunchEC2Fleet":{
         "Type":"AWS::EC2::EC2Fleet",
         "Properties":{
            "LaunchTemplateConfigs":[
               {
                  "LaunchTemplateSpecification":{
                     "Version":"$Latest",
                     "LaunchTemplateId":{
                        "Ref":"MainEC2FleetLaunchTemplate"
                     }
                  }
               }
            ],
            "TargetCapacitySpecification":{
               "DefaultTargetCapacityType":"on-demand",
               "TotalTargetCapacity":1
            },
            "Type":"instant"
         }
      },
      "EIP":{
         "Type":"AWS::EC2::EIP",
         "Properties":{
            "Domain":{
               "Ref":"VPC1"
            }
         },
         "DependsOn":"LaunchEC2Fleet"
      },
      "EIPAllocation":{
         "Type":"AWS::EC2::EIPAssociation",
         "Properties":{
            "EIP":{
               "Ref":"EIP"
            },
            "InstanceId":{
               "Ref":"LaunchEC2Fleet"
            }
         }
      }
   }
}```

相关内容