Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nathanpeck opened this issue Nov 13, 2018 · 2 comments · Fixed by #1170
Closed

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

nathanpeck opened this issue Nov 13, 2018 · 2 comments · Fixed by #1170
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container @aws-cdk/aws-elasticloadbalancing Related to Amazon Elastic Load Balancing good first issue Related to contributions. See CONTRIBUTING.md

Comments

@nathanpeck
Copy link
Member

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.

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 13, 2018

Edit: ah no, you're right.

@rix0rrr rix0rrr added good first issue Related to contributions. See CONTRIBUTING.md @aws-cdk/aws-elasticloadbalancing Related to Amazon Elastic Load Balancing @aws-cdk/aws-ecs Related to Amazon Elastic Container labels Nov 13, 2018
rix0rrr added a commit that referenced this issue Nov 14, 2018
When ALB listener rules are used, the ordering dependency for services
that require an attachment to a Load Balancer has to be on the
`AWS::ElasticLoadBalancingV2::ListenerRule` object, not on the
`Listener` object (as the current implementation does).

Fixes #1160.
rix0rrr added a commit that referenced this issue Nov 14, 2018
When ALB listener rules are used, the ordering dependency for services
that require an attachment to a Load Balancer has to be on the
`AWS::ElasticLoadBalancingV2::ListenerRule` object, not on the
`Listener` object (as the current implementation does).

Fixes #1160.

BREAKING CHANGE: `targetGroup.listenerDependency()` has been renamed to
`targetGroup.loadBalancerDependency()`.
@RafeArnold
Copy link

RafeArnold commented Aug 16, 2024

Not sure if it will be seen here, but I don't understand why the service would have to depend on any of the other declared resources (load balancer, listener, target group). Surely the service can exist independently of any of these other resources, and rather should be a dependency of the other resources?

I'm bringing this up because I want to conditionally create a load balancer and target group containing a service that will always exist, but CloudFormation cannot construct the service when the load balancer isn't created because the service depends on the load balancer listener. When I don't add the load balancer and target group ever (i.e. don't declare them at all), the service can be created just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container @aws-cdk/aws-elasticloadbalancing Related to Amazon Elastic Load Balancing good first issue Related to contributions. See CONTRIBUTING.md
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants