Tasks with public IP on EC2 backed ECS

0

I want to run ECS tasks on EC2 backed ECS with public IP. My tasks generates a lot of outgoing traffic and I do not want to pay for NAT.

It turned out that it is absolutely possible using Fargate backed ECS and not with EC backed.

When I create following task definition

const taskDefinition = new ecs.Ec2TaskDefinition(this, `${this.appPrefix}-task-definition`, {
   networkMode: ecs.NetworkMode.AWS_VPC,
});

and set assignPublicIp: true for my service I receive an error during deployment:

Assign public IP is not supported for this launch type.

So my question is it possible to run ECS tasks with public IP on EC2 backed cluster?

profile picture
Smotrov
已提问 3 个月前233 查看次数
1 回答
0

Hello.

If the network type is "awsvpc" for EC2 launch type ECS, you cannot set a public IP address.
So, if you need a public IP, I think you need to set the network mode to host mode or bridge mode.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking-awsvpc.html

When hosting tasks that use the awsvpc network mode on Amazon EC2 Linux instances, your task ENIs aren't given public IP addresses. To access the internet, tasks must be launched in a private subnet that's configured to use a NAT gateway. For more information, see NAT gateways in the Amazon VPC User Guide. Inbound network access must be from within a VPC that uses the private IP address or routed through a load balancer from within the VPC. Tasks that are launched within public subnets do not have access to the internet.

profile picture
专家
已回答 3 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则