Yesterday I was using an AWS CloudFormation template to ultimately create an ECS Service (Fargate type), but also create resources including an Application Load Balancer, Target Group and IAM Roles.
When the stack was being created, I received the following error:
The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:599074885545:targetgroup/a204516-S2S-Sandbox-TargetGroup/9f4aa2eb4051a952 does not have an associated load balancer. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: 5da2a1ed-a216-4666-a6f9-8af18ef37af6)
I inspected my template a number of times, and felt it was correct. I found a post on a forum suggesting the error may be due to the fact the Load Balancer may not have been created yet by the time the ECS Service was being created.
The solution: Use the DependsOn attribute for the ECS Service resource.
Here is a portion of my AWS CloudFormation Template, using the DependsOn attribute:
Published on Java Code Geeks with permission by Steven Wall, partner at our JCG program. See the original article here: AWS CloudFormation: Target Group does not have an associated Load Balancer
Opinions expressed by Java Code Geeks contributors are their own.