ecs register-task-definition portMappings does not accept containerPort + hostPort
Describe the bug
Hi, I would like to set up a task definition with ports 3000:7000, I am running the following code:
aws ecs register-task-definition --family %name% --task-role-arn %ecs_role_arn% --execution-role-arn %ecs_role_arn% --container-definitions name=%container_name%,image=%container_uri%,memory=128,portMappings="[{"containerPort"="3000"},{"hostPort"="7000"},{"protocol"="tcp"}]"
This is what i get:
An error occurred (ClientException) when calling the RegisterTaskDefinition operation: Invalid 'containerPort' setting for container 'container_1'.
Also, the strange thing is that this worked:
"[{"containerPort"="7000"},{"containerPort"="7000"}]"
Expected Behavior
I should be able to input 3000 for containerport and 7000 for hostport
Current Behavior
"containerPort"="3000" seems to be causing the issue
Reproduction Steps
aws ecs register-task-definition --family %name% --task-role-arn %ecs_role_arn% --execution-role-arn %ecs_role_arn% --container-definitions name=%container_name%,image=%container_uri%,memory=128,portMappings="[{"containerPort"="3000"},{"hostPort"="7000"},{"protocol"="tcp"}]"
Possible Solution
No response
Additional Information/Context
No response
CLI version used
aws-cli/2.7.0 Python/3.9.11 Windows/10 exe/AMD64 prompt/off
Environment details (OS name and version, etc.)
Windows 11
Hi @arditobryan, thank you for opening your first issue in AWS CLI repo and sorry to hear you're having trouble.
I tried to reproduce with the command provided with CLI v2.7.31 and wasn't able to get the same behavior as you described. Does your task definition use awsvpc or bridge network mode? Please note that if they're in awsvpc network mode, you should only specify the containerPort. The hostPort must be either the same value as containerPort or can be left blank.
Here's docs reference:
For task definitions that use the awsvpc network mode, only specify the containerPort . The hostPort can be left blank or it must be the same value as the containerPort.
Hope it helps, but If you're still having issue, please share your debug logs by adding --debug in your command.
Best, John
Thank you @aBurmeseDev
aws ecs register-task-definition --family %name% --task-role-arn %ecs_role_arn% --execution-role-arn %ecs_role_arn% --network-mode bridge --container-definitions name=%container_name%,image=%container_uri%,memory=128,portMappings="[{"containerPort"="7000"},{"hostPort"="7000"},{"protocol"="tcp"
I updated the query to use --network-mode bridge, to make it easier I would like to set a containerport=7000, hostport=7000 like in the image below (I am deckerizing a fastapi application).
This is the desired result:

Hi @arditobryan - I wanted to check in to see if you were able to set the host and container posts. I would follow the steps from the docs linked above if you're still having issues.
Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.