Closed revmischa closed 3 years ago
One thing that jumps out to me is lemmyService.registerLoadBalancerTargets
. This is a method, which takes a list of targets to register to the listener; the code is not calling the method, or passing in the targets. You could opt to use that method instead.
That being said, your above approach would work, but you need to use service.loadBalancerTarget
. See the docs for details, but this allows you to specify a non-default container as the target:
lemmyLoadBalancer.backendTargetGroup.addTarget(lemmyService.loadBalancerTarget({
containerName: BACKEND_NAME,
});
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.
One thing that jumps out to me is
lemmyService.registerLoadBalancerTargets
. This is a method, which takes a list of targets to register to the listener; the code is not calling the method, or passing in the targets. You could opt to use that method instead.That being said, your above approach would work, but you need to use
service.loadBalancerTarget
. See the docs for details, but this allows you to specify a non-default container as the target:lemmyLoadBalancer.backendTargetGroup.addTarget(lemmyService.loadBalancerTarget({ containerName: BACKEND_NAME, });
This ended my headache, I was targeting the service alone and both target groups were going to one port instead of separate ports, heres the change I made, perviously it said targets: [bshFargateService] for both.
const backendTargetGroup = new elbv2.ApplicationTargetGroup(
this,
'bsh-be-tg',
{
port: 8080,
protocol: elbv2.ApplicationProtocol.HTTP,
targets: [
bshFargateService.loadBalancerTarget({
containerName: backendContainer.containerName,
}),
],
vpc: ec2.Vpc.fromLookup(this, 'jh-imported-vpc-tg-be', {
vpcId: props.aws_env.AWS_VPC_ID,
}),
healthCheck: {
path: '/healthcheck',
unhealthyThresholdCount: 2,
healthyHttpCodes: '200',
healthyThresholdCount: 5,
interval: cdk.Duration.seconds(30),
port: '8080',
timeout: cdk.Duration.seconds(10),
},
}
);
const frontendTargetGroup = new elbv2.ApplicationTargetGroup(
this,
'bsh-fe-tg',
{
port: 3000,
protocol: elbv2.ApplicationProtocol.HTTP,
targets: [
bshFargateService.loadBalancerTarget({
containerName: frontendContainer.containerName,
}),
],
vpc: ec2.Vpc.fromLookup(this, 'jh-imported-vpc-tg-fe', {
vpcId: props.aws_env.AWS_VPC_ID,
}),
healthCheck: {
path: '/api/healthcheck',
unhealthyThresholdCount: 2,
healthyHttpCodes: '200',
healthyThresholdCount: 5,
interval: cdk.Duration.seconds(30),
port: '3000',
timeout: cdk.Duration.seconds(10),
},
}
);
I've created an ECS fargate service with three different containers on different ports. I would like to add this ECS service to three different TargetGroups, with the different target groups corresponding to the different services.
Reproduction Steps
You can see the full setup here: https://github.com/jetbridge/lemmy-cdk/tree/ecs-single-service/lib/lemmy
What did you expect to happen?
What I want is each container to be mapped to each target group. I would expect the ALB to send traffic to the various containers on their respective ports.
What actually happened?
ECS creates three target group associations with only one container on its port.
Environment
Other
Basically I want to have a single task definition with multiple containers, where the containers each go into their own target groups. Instead the target groups only associate with the first container in the service.
This is :bug: Bug Report