[英]CDK: Use a UDP port mapping with NLB and ECS/Fargate service
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.我在为网络负载平衡 Fargate 服务添加端口映射时尝试使用 UDP 端口,但
cdk
构建失败并出现以下错误。
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发现其他几个人遇到了同样的问题: 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?是否可以使用 CDK 为网络负载平衡 Fargate 服务配置 UDP 端口?
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.我找到了解决方法,最初在容器映射中将端口添加为 TCP 端口,然后使用 Cfn 进行覆盖以更改为 UDP。
container.addPortMappings({
containerPort: 7950,
hostPort: 7950,
protocol: EcsProtocol.TCP
}
);
const td = this.service.taskDefinition.node.defaultChild as CfnTaskDefinition;
td.addPropertyOverride('ContainerDefinitions.0.PortMappings.0.Protocol', 'udp');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.