I am trying to use UDP port when adding port mapping for a Network load balanced Fargate service but cdk
build fails with below error.
Error: Container '**-ECS-Task-Container' has no mapping for port undefined and protocol tcp. Did you call "container.addPortMappings()"?
at FargateTaskDefinition._validateTarget (/../node_modules/aws-cdk-lib/aws-ecs/lib/base/task-definition.js:1:7371)
at FargateService.loadBalancerTarget (/../node_modules/aws-cdk-lib/aws-ecs/lib/base/base-service.js:1:9940)
at FargateService.get defaultLoadBalancerTarget [as defaultLoadBalancerTarget]
Relevant code:
const container = taskDefinition.addContainer(props.stackName + '-ECS-Task-Container', {
containerName: props.stackName + '-ECS-Container',
image: serviceImage,
memoryLimitMiB: 512,
cpu: 256,
portMappings: [
{
containerPort: 7950,
hostPort: 7950,
protocol: EcsProtocol.UDP
},
]
});
}
or,
container.addPortMappings({
containerPort: 7950,
hostPort: 7950,
protocol: EcsProtocol.UDP
}
);
Found that the same issue was encountered with couple others: https://github.com/aws/containers-roadmap/issues/445#issuecomment-714930539
Is it possible to use configure UDP port for Network load balanced Fargate service using CDK?
I found a work around, initially in container mappings added the port as TCP port, then done an override using Cfn to change to UDP.