Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CF Template for provisioning new EC2 instance with Existing Targetgroup

I'm trying to provision a new EC2 instance and attaching it to the existing targetGroup which I created earlier. I do have the targetGroupArn, and the new instance details. In all the documents, I could see the sample templates of creating a new instance and new targetgroup and referring the instance id to the creating targetgroup.

Is there any option to create only new instance and attaching it to the existing target group?

So that I can mention the targetGroupArn to which the new instances will be attaching. Below I've mentioned the sample templates, what I'm looking for.

{
  "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
  "Properties": {
    "TargetGroupArn": "arn:aws:elasticloadbalancing:ap-south-1:4444444444:targetgroup/MyTG/56abcccccccc56",
    "Targets": [
      {
        "Id": {
          "Ref": "ec2Instance1"
        }
      }
    ]
  }
}
like image 501
Sonu Avatar asked Dec 02 '25 22:12

Sonu


1 Answers

Is there any option to create only new instance and attaching it to the existing target group?

Yes, you can do that through a custom resources in the form of a lambda function. The function would use AWS SDK, such as boto3, to attach the instances to the existing target group.

like image 109
Marcin Avatar answered Dec 04 '25 11:12

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!