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"
}
}
}
}
}```