I’m using ECS + Fargate for the first time. Uploaded a new version of my image on ECR (tagged ‘latest’) and I want to update the running task to use it.
For what I read, I should run “aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment” and that’s it. Also I can do this through AWS portal, if I go to Service → Update.
Now my question: Do this procedure change the public IP my ENI is given? I have this doubt as I think -force-new-deployment kills the tasks and creates a new one, so another ENI is used.
I would need to mantain the public IP if it’s possible.
Oops, sorry, I missed the Fargate part. I’ve never used Fargate so I don’t know for sure.
If your IP address is not an Elastic IP, then anything that removes the ENI will likely lose that address. I don’t know whether a task update would do that.
If the IP address is an Elastic IP, then you may still lose the association between the IP and the task but in a way which should be repairable afterwards.
If I were doing this and needed a static IP for inbound traffic, then I would get myself an Elastic IP, attach it to an Application Load Balancer, and use weighted routing to control which version of the service is publicly available. Using DNS instead of IP addresses would also help here so that the IP could change, but the hostname wouldn’t.
If this is for outbound traffic, then putting your Elastic IP on a NAT gateway may help, so that connections initiated by the ECS task always had the same source IP address. This would have to be combined with an ALB also, but the ALB would have a standard public IP (which may change) and you’d probably use DNS to get inbound traffic to your ALB without clients having to worry about what its IP is
IMO you are looking for pain if you expect the IP not to change (if it isn’t one you’ve allocated and have dedicated). Get away from that as fast as possible.
With Fargate, we’ve had the best success with using CloudFormation. We simply update the (versioned) Docker tag and it adds the new tasks and scales down the old ones. Virtually no downtime.
Keep in mind that load balancers are expensive, so if you’re only running one small ECS task then it may be cheaper to spin up a dedicated EC2 and use web hooks to redeploy when you push new images
If your need for a public IP is because you’ve allowed it access to your on-prem resources, a load balancer won’t help you - those are for inbound traffic to your container as a web service.
If you need a fixed outbound IP, you’ll want to run your tasks in a private subnet, and set up a NAT gateway in a public subnet. The IP address of the NAT gateway will be the one that you allow into your on-prem resources.
Alternatively, you could set up a small EC2 instance in a public subnet to perform NAT if you don’t want to spend on the NAT gateway.
In this case you’ll need some form of NAT gateway. The AWS NAT Gateway’s can become quite expensive, but I’ve heard it’s possible to just run your own NAT instance on a t3.micro or similar lower cost instance.
And if you want static IPs in front of your ELB, a Global Accelerator is a cheap way to get two static IPs in front of it with a bonus of faster routing.
Wow TIL you can do Fargate without an ALB. The thought of using Fargate without an ALB in front never crossed my mind before. I guess it’s useful if you are only doing outgoing connections and don’t care about stuffs coming in.
I would maybe add on to this that nowadays for new stacks you’re probably better off using CDK. Especially ECS/FARGATE gets pretty complex in CF alone. It took me like a day to get up my first stack.