0

I am creating multiple EC2 instances using EC2 Fleet service in cloudformation, I want to assign elastic IP addresses to newly created instances from EC2 Fleet,

below is my template,

can anyone help with this, thank you in advance.

   "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"
            }
         }
      }
   }
}```
  • What problem are you having? What happens when you execute the template? Also curious why they need elastic IPs, load balancing would be more common but it depends on what they're doing whether that will help. – Tim Jun 22 '22 at 19:40
  • actually i want to create server with static IPs because of that i need elastic IP, but the issue is ec2 fleet does not return Instance ID it returns on fleet ID, then how can i assign EIP to the instances without Instance ID. Your help will be appreciated Thanks for the reply – Darshan Palsamkar Jun 23 '22 at 09:02
  • Without looking into it in detail the general answer for anything complex or custom in AWS is "write a lambda function". – Tim Jun 23 '22 at 09:59
  • any other way to do from cloudformation?? – Darshan Palsamkar Jun 23 '22 at 11:31
  • I don't know for sure, I find the json format difficult to read, and I would have to spend some time with the documentation to work it out. I also think you're probably taking the wrong approach with EIPs for every server in a fleet. – Tim Jun 23 '22 at 20:00

0 Answers0