question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(ecs-patterns): Expose arrays of load balancers, listeners, and targetGroups as properties in ApplicationMultipleTargetGroupsFargateService and other patterns constructs

See original GitHub issue

I want to utilize the construct ApplicationMultipleTargetGroupsFargateService for creating a Fargate service fronted by an Application Load Balancer. I need the Application Load Balancer to have 2 listeners and each listener to forward traffic to a distinct ApplicationTargetGroup.

The problem I run is after I instantiate the construct, and want to configure health checks for each individual target group. The ApplicationMultipleTargetGroupsFargateService provides a targetGroup property, however, according to the CDK documentation, this only contains a reference to the default Target Group. Ideally, this would contain a list of references to the different ApplicationTargetGroups configured within the construct. Is there any method for getting a reference to these additional target groups in the CDK from the construct for configuring health checks?

const service = new ApplicationMultipleTargetGroupsFargateService(this, 'ALBFargateService', {
    cluster: this.ecsALBCluster,
    taskDefinition: taskDefinition,
    desiredCount,
    assignPublicIp: true, // needed for outbound network connectivity in a public subnet
    serviceName: 'ALBFargateService',
    loadBalancers: [
        {
            name: 'ApplicationLoadBalancer',
            listeners: [
                {
                    name: 'TrafficListener',
                    port: 443,
                    protocol: ApplicationProtocol.HTTP
                },
                {
                    name: 'HealthCheckListener',
                    port: 8050,
                    protocol: ApplicationProtocol.HTTP
                }
            ]
        }
    ],
    targetGroups: [
        {
            listener: 'TrafficListener',
            containerPort: 443,
            protocol: Protocol.TCP
        },
        {
            listener: 'HealthCheckListener',
            containerPort: 8050,
            protocol: Protocol.TCP
        }
    ]
});

service.targetGroup.configureHealthCheck({
    port: '8050',
    protocol: elbv2.Protocol.HTTP,
    healthyThresholdCount: 2,
    unhealthyThresholdCount: 2,
    timeout: Duration.seconds(10),
    interval: Duration.seconds(30),
    healthyHttpCodes: '200'
});

// TODO: Configure Health Checks for second target group on port 8050

As shown above, I am configuring the service with 2 listeners and 2 target groups associated with a respective listener. Only the first target group’s reference is accessible via the targetGroup property.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
peterwoodworthcommented, Aug 14, 2021

You can work around this by using escape hatches

const lb = service.node.children[x] as ApplicationLoadBalancer
console.log(lb.listeners)

x is whatever number child your ApplicationLoadBalancer is. You can see this by doing console.log(service.node.children)

0reactions
github-actions[bot]commented, Aug 5, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class ApplicationMultipleTargetGroupsFargateService ...
A Fargate service running on an ECS cluster fronted by an application load balancer. Example. // One application load balancer with one listener...
Read more >
awsecspatterns
This library provides higher-level Amazon ECS constructs which follow common architectural patterns. It contains: Application Load Balanced Services ...
Read more >
Unused AWS ELB Resources
Find any unused Amazon Application Load Balancers (ALBs) and Network Load Balancers (NLBs) and remove them from your account in order to help...
Read more >
ecs-patterns 1.182.0 javadoc (software.amazon.awscdk)
One application load balancer with one listener and two target groups. Cluster cluster; ApplicationMultipleTargetGroupsFargateService ...
Read more >
@aws-cdk/aws-elasticloadbalancingv2 | ...
Amazon Elastic Load Balancing V2 Construct Library. cfn-resources: Stable. cdk-constructs: Stable. The @aws-cdk/aws-elasticloadbalancingv2 package provides ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found