Enterprise Java

AWS CloudFormation: Target Group does not have an associated Load Balancer

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)

1
The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:999999995545:targetgroup/MyTargetGroup/999999eb4051a952 does not have an associated load balancer. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: 54321987-a2a2-4444-abcd-8af18ef12345)

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:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
#Create Application Load Balancer
  DemoApplicationLoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Type: application
      Name: Demo-ALB
      IpAddressType: ipv4
      Scheme: internet-facing
      # Other properties...
 
# Create Security Groups, IAM Roles, Load Balancing Listener, ECS Cluster, ECS Task Def, etc.
 
# Create ECS Service - with DependsOn attribute
  DemoSandboxService:
    Type: AWS::ECS::Service
    DependsOn:
    - DemoLoadBalancerListener
    Properties:
      Cluster:
          Ref: DemoSandboxCluster
      # Other properties...

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.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button