Is there any reason not to use Fargate with public IPs? You have to lock container access down, but you have to do that anyway. It makes things marginally easier, because you don’t have to add NAT and the routes to the VPC/subnets. But really, are there any downsides besides the obvious security aspects?
Mostly security: it’s not very hard to setup NAT or a load-balancer and you avoid an entire class of concerns that way.
One other thing: if you use a load-balancer, you can replace containers easily. If you’re sending traffic to public IPs it’ll keep going until all clients expire their cached DNS results. This may not be a big deal depending on your app.
It depends whether or not your container’s workload is ‘inside-out’. If your containers are not serving connections from outside, it really doesn’t matter if you have public IPs or not. You can just lock down the security group and go about your business. If this container will be the target of connections from outside, there are multiple reasons not to do this, lots of which have already been written in other comments.
scaling the ecs without a load balancer is not harder than with, controlling the traffic flow can be harder given ecs can only do weighted or multivalue dns
Yes, but then you have DNS lookups adding to your response time - mostly a problem for things which you want public IPs for - and you still don’t have an answer other than timeouts and retries for persistent connections handling multiple requests.
There isn’t an unambiguous yes or no answer here, just factors to consider for your application.
that doesn’t really make sense. you have to send the traffic to either the load balancer or the public ip, so why would you not just use a public elb and leave the actual node on a private NATed subnet? what benefit would the public ip on the ecs node serve here?
It makes perfect sense and is a common pattern. Inbound traffic directly to a public IP isn’t protected by Shield and using a private IP means you will likely need to run a NATGW.
so having the public ip purely for outbound traffic? I just don’t see why that would be more beneficial over just using a natgw, other than for a very specific requirement.
Cost, scaling, accessibility… there are plenty of common reasons. There are plenty of small and large companies that have ALL their instances in public subnets and use this technique. It can lead to an overall simpler infrastructure with no trade offs provided you actually manage your security groups properly.
So like I said, it absolutely makes perfect sense why you would do this.
The reason I’m asking is that I accidentally created a couple of Fargate containers in my public IP subnet, and they were publicly accessible. The only reason I noticed was I was browsing through some part of the console and saw that the containers had public IPs (which was unexpected). I verified they could get out by pushing a container out that pulled a a resource from the outside.
I’ve got an ALB in front of all that, and locked down the security group on the containers so only the ALB could get to them.
Upon reflection, it seems that this would be an interesting, though risky, way to be able to allow direct container access for debugging; you could open the SG to just your IP if you needed to get to the container directly. Since you can’t have a fargate bastion host this seems to be the only way to do it (mainly for debugging/troubleshooting).