Skip to content

AWS::ECS::Service needs DependsOn AWS::ElasticLoadBalancingV2::ListenerRule #1160

@nathanpeck

Description

@nathanpeck
22/26 | 10:15:33 | CREATE_FAILED        | AWS::ECS::Service                         | greeting-service/Service (greetingserviceService8DA58640) The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:209640446841:targetgroup/greet-inter-7A1DWCFAH8FU/c4bab708f6cad935 does not have an associated load balancer. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: f6e72ff4-e756-11e8-afbf-dd214588018c)

When creating a service and adding it to a load balancer the CloudFormation template fails to deploy with the above error. Example code:

const greeterService = new ecs.Ec2Service(this, 'greeter-service', {
      cluster: cluster,
      desiredCount: 2,
      taskDefinition: greeterTaskDefinition
    });

     // Internet facing load balancer for the frontend services
    const externalLB = new elbv2.ApplicationLoadBalancer(this, 'external', {
      vpc: vpc,
      internetFacing: true
    });

    const externalListener = externalLB.addListener('PublicListener', { port: 80, open: true });

    externalListener.addTargets('greeter', {
      port: 80,
      targets: [greeterService]
    });

This is probably happening because the AWS::ECS::Service resource needs a DependsOn to the AWS::ElasticLoadBalancingV2::ListenerRule resource. Otherwise it is a race condition that causes a failure if the service resource creation starts before the listener rule is ready.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions