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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南