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
asked 3 months ago208 views
1 Answer
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
EXPERT
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions