Understanding AWS compute options part 2

Understanding AWS compute options part 2
Photo by Joshua Ferdico / Unsplash

ECS vs. Apprunner vs. Lambda
A comparison of serverless compute options on AWS.

This is part 2 on a series of posts on AWS compute options where we look at serverless compute. For part 1 (server-based) click here.

We will look at serverless options specifically. In serverless computing, the server and underlying infrastructure is abstracted away from developers. So all you and I have to focus on is the actual application code. This frees up time and means more time can be used to optimize and develop application code, adding features and reaching business goals.

As always with AWS, there is a plethora of various options. Let's dive in!

ECS with Fargate - The King Of Serverless

Setting up an ECS instance.

For an in-depth explanation of ECS check out this post.

The 'EC2' of serverless. ECS stands for Amazon Elastic Container Service. It is a container orchestration service that allows us to run and manage containerized Docker applications. It is also possible to use ECS with EC2 but here we focus on serverless so we look at Fargate. Fargate is simply the service that provides serverless compute.

Ease of use:

The learning curve is a bit high on this one. There is less transparency since there are no servers. So if something goes wrong in your application you need to rely on logs to figure out the problem. It is possible to SSH into a serverless instance. But this has only recently been added as a feature and does not mean that you can go about and treat it like you would a server.

Cost:

Serverless means a lot of maintenance is taken off your hands. That comes at a high price. It costs $10.37/month for a 0.25 vCPU and 0.5 GB of RAM. In comparison the smallest EC2 instance is 2 vCPUs and 0.5 GB RAM and costs $3.50/month.

That is about 3 times as costly for 8 times less the compute power!

Scalability:

Highly scalable just like EC2. Full points here.

Maintenance:

No maintenance. You only need to care about your application code. Full marks.

When to use it:

If you have the budget and not the developer resources to manage servers.
This also makes sense for a microservice architecture where there are a lot of services and resources running. Running them in multiple EC2 can be cumbersome since each one of the servers would have to be monitored and manually maintained.

App runner - Serverless Compute For Web Applications

Setting up an Apprunner instance

A relatively new service and only available in certain AWS regions. This offers a higher level of abstraction than ECS on Fargate. Networking, load balancers, security groups and the like are automatically created and managed when creating an App runner instance. Compared to ECS where these things need to be manually created and configured.

Ease of use:

Scores very high points in this category. It is super simple to set up. You just need to specify a container image, choose compute size and configure concurrency. The rest is created for you.

Cost:

The smallest size is 1 vCPU and 2 GB RAM and costs $56/Month. It is relatively expensive. ECS with Fargate with the same compute options costs $36/Month.  
There is a very nice article here providing a cost breakdown on ECS vs. App Runner. Essentially, App Runner is cheaper for small workloads with longer idle periods.  

Scalability:

Scores high points like everything else in the serverless category.

Maintenance:

Scores very high points again as it is a fully managed service so AWS takes care of most things.

When to use it:

Apprunner only supports synchronous TCP/HTTP connections. So it is catered exclusively to web applications. This sets it apart from ECS on Fargate where you can run whatever kind of workload you desire such as batch processing, asynchronous processing or UDP applications.
So it is a good choice if you wish a serverless solution for your web application.

Lambda - Serverless Functions In The Cloud

Setting up a Lambda function

This is a very specific service that basically is a FaaS (function as a service).
You define the code to run and the trigger. The code runs when triggered.

Ease of use:

Very simple. You simple define what code needs to run and when. Full marks.

Cost:

Cost is a bit harder to estimate since you pay per request and, function execution time and other parameters. A mobile application backend using Lambda with 3 million requests per month, 1536 MB of memory and 120 ms function duration would cost $2.73/month. This is including the free tier of 1 million requests per month.

Scalability:

Highly scalable. There is no need to think about how many requests are coming in. If you can pay for it that is.

Maintenance:

Full marks. No maintenance.

When to use it:

Repetitive tasks that need to run on known triggers. So functions that need to run based on triggers. Examples include image resizing that needs to occur every time an image is uploaded to S3. This would typically be part of a larger infrastructure, where main computation/hosting takes place on EC2 or ECS.

Wrap-Up

Hope you enjoyed this post.

To summarize, ECS is used for diverse workloads, while Apprunner is suited to web applications. Finally, Lambda is in a category of itself used for one-off functions that need to be run based on triggers.


Have any questions? Leave a comment below 😇

I hope you liked this post.
I am planning on releasing premium content in the future.
Please consider subscribing below to gain exclusive access.