[ECS] container enforces having port mappings
See original GitHub issueDescribe the bug Should be able to create ECS container with no port mappings. This error occurs when trying to do so:
Error: Container test hasn't defined any ports. Call addPortMappings().
To Reproduce Create an ecs cluster with a Ec2TaskDefinition that has a container with no port mappings specified.
Expected behavior Should be able to have a container with no port mappings.
Version:
OS: Win10 Programming Language: Typescript CDK Version: 0.28.0
There are cases a container is behind a reverse proxy so it doesn’t need any port mapping.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:15 (7 by maintainers)
Top Results From Across the Web
PortMapping - Amazon Elastic Container Service
Port mappings allow containers to access ports on the host container instance to send or receive traffic. Port mappings are specified as part...
Read more >Task definition parameters - Amazon ECS - 亚马逊云科技
Port mappings allow containers to access ports on the host container instance to send or receive traffic. For task definitions that use the...
Read more >port mapping for AWS ECS - Stack Overflow
All we need is container port. Host port will be randomly assigned and when we scale containers we have no issues. – Balu...
Read more >Use Port Forwarding to Access Applications in a Cluster
Before you begin You need to have a Kubernetes cluster, and the kubectl ... --template='{{(index (index .spec.containers 0).ports 0).
Read more >Deploy to Amazon Elastic Container Service - GitLab Docs
Add a port mapping. Set 80 to Host Port and 5000 to Container port. ... Select Create. Make sure that the ECS cluster...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @yanyansk , thanks for providing your task definition. When using the
service
object as target for the Application Load Balancer (ALB) here:it uses the first essential container (in the error case it is the Firelens log router) as the target.
cdk synth
will throw this error as the LB target is expected to have an exposed port while the Firelens log router doesn’t have one. When theapp
container is added before the log router, it becomes the default essential container and as it has an exposed port, no errors are thrown on doingcdk synth
.You’ll either need to add the container with exposed ports first or you can also add the ALB target like so:
The
loadBalancerTarget()
function can be used to create a target if you want to load balance to a container other than the first essential container (so the containers can be added in any order) or the first mapped port on the container.For future reference, in case anyone else comes across this issue, it was caused by the order that containers are defined in. If you define a container without ports before a container with ports then you get the error. Switch the order in which you call
addContainer
so the one with ports open is first and it works fine.