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
demandé il y a 3 mois232 vues
1 réponse
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
répondu il y a 3 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions