2 Answers
- Newest
- Most votes
- Most comments
1
In AWS ECS, when using the awsvpc network mode, each task gets its own Elastic Network Interface (ENI) and the security group is attached to this ENI, however, these ENIs are fully managed by Amazon ECS and cannot be detached manually or modified. Instead of defining the security group at the task level, it is necessary to set it at the Elastic Network Interface (ENI).
0
Self answer. Adding security group doesn't works. I don't know why....
ingestEC2NlbServicePublic.service.connections.addSecurityGroup(taskSG);
Meanwhile, if I use allowFrom it works like a charm.
const { connections } = ingestEC2NlbServicePublic.service;
connections.allowFrom(
elbSG,
ec2.Port.tcp(HEALTH_CHECK_PORT),
'Allow traffic from within the VPC to the service health check port',
);
connections.allowFrom(
elbSG,
ec2.Port.tcp(CONTAINER_PORT),
'Allow traffic from within the VPC container port',
);
I suspect it is CDK bug.
Relevant content
- asked a year ago
- asked a year ago
- asked 3 years ago

Than you for prompt reply. I do understand how to do it in the console. The question is how to do it using CDK. Any hints?
something like this may work