Skip to content

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

@evanj354

Description

@evanj354

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecs-patternsRelated to ecs-patterns libraryeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.feature/enhancementA new API to make things easier or more intuitive. A catch-all for general feature requests.p1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions