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"
}
}
]
}
}
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.