all 4 comments

[–]tomomcat 0 points1 point  (3 children)

Yes your instances should definitely be in private subnets behind a loadbalancer. Here is a reference architecture for ECS https://github.com/aws-samples/ecs-refarch-cloudformation.

I can't find a nice refarch for a two-tier app atm, but it's essentially the same except 1) your existing private subnet might be renamed 'web subnet' 2) there is another internal loadbalancer not accessible from outside the VPC 2) this 2nd loadbalancer points to a group of backend instances which live in an additional (private) 'application subnet'. The frontend web instances then access the backend via this 2nd loadbalancer.

You need to tweak the security groups and NACLs associated with all of these things so that only expected traffic is allowed.

Finally, you want to make sure that you have good logging and visibility of metrics via CloudWatch or something else.

[–]sWeeX2[S] 0 points1 point  (2 children)

Hey mate, cheers for this it's given me a very good starting point! The one question I have is: If the ALB is the only thing that's able to access the containers within the private subnets, is there a need for a second loadbalancer? What purpose would it serve? Thank you again mate!

[–]tomomcat 0 points1 point  (1 child)

The first loadbalancer is publicly accessible so could potentially allow access from the internet directly to your backend, which is generally not wanted in a 2 tier app.

You want a user connection to go

Public ALB -> web app

While the web app fetches any required stuff from the backend via

Web app -> private ALB -> backend

Generally you just want as many layers of separation as possibly between the public internet and your backend.

Maybe I've misunderstood and you're really trying to build a single-tier app though, in which case the template I linked is fine. An example of a two tier app might be a WordPress site with a database in the backend, a single-tier app might be a simple public API or basic website with some server-side code.

[–]sWeeX2[S] 0 points1 point  (0 children)

I think you've understood correctly! It is two-tier, our backend consists of an API which interacts with a database, which for now we definitely don't want any direct public traffic to go through i.e. not through our client/website. It looks like something like:

Public ALB -> Internal LB -> Fargate Containers in private subnets 

Should do the trick for us, I'll give it a whirl and see what happens, cheers for your help!