Restful Compute Power - EC2 vs. ECS Fargate vs. Lambda


This post is one in a series of posts that are sample chapters from my FREE eBook 20 Things You Can DoTo Save Money On Your Amazon Web Services Bill Today. Feel free to download the full eBook for free if you want the whole thing.

Restful Compute Power - EC2 vs. ECS Fargate vs. Lambda:

Let’s start with something basic like your restful web server. Here, we have a range of options, with EC2 being on one side and Lambda on the other, with EC2 being the most cumbersome to scale up and down and Lambda being the easiest, with ECS somewhere in the middle.

Depending on how far you want to go with your cost-cutting, you could scale down to just using an “On Demand” solution like AWS Lambdas. APIGateway paired up with AWS Lambdas makes an awesome combination and is my go-to for my one-off experimental projects or apps that may go for a while without traffic because it scales down to zero cost if no one there is no traffic.

Limitation on Languages:

Officially, AWS Lambda only supports a few languages out of the box, like NodeJS, Python, Go, and a few more. So what if you are running something else like PHP? Well, I am not advocating for you to do this, but it is possible to run your own custom docker containers on AWS Lambda. I did it once as an experiment. I'm not sure I would recommend it for production, but it is something worth looking into.

AutoScaling:

Both ECS and EC2 have auto-scaling abilities, with EC2 being the slower of the slowest and ECS (at least on Fargate) being vastly faster. Now, if you are using either of these compute resources as a restful web server or even a socket server, I don't think it would be practical to scale these down to zero if there is no traffic, as scaling back up when traffic comes in would take too long.

Scaling to zero is actually possible with EC2 and ECS, just not for web servers. We will talk about this more when we get to the async workers.

Helpful Links:

AWS APIGateway Pricing: https://aws.amazon.com/api-gateway/pricing/ AWS Lambda Pricing: https://aws.amazon.com/lambda/pricing/ AWS Lambda Supported Languages: https://aws.amazon.com/lambda/faqs/#:~:text=Q%3A%20What%20languages%20does%20AWS,languages%20to%20author%20your%20functions. AWS Lambda Custom Docker Images: https://docs.aws.amazon.com/lambda/latest/dg/images-create.html Schematical’s Open source APIGateway Module: https://github.com/schematical/sc-terraform/tree/main/modules/apigateway-env Schematical’s Open source Lambda Service Module: https://github.com/schematical/sc-terraform/tree/main/modules/lambda-service