Table Of Contents
What Is AWS Fargate? What Is AWS Lambda? AWS Lambda Vs. AWS Fargate: Cost AWS Lambda Vs. AWS Fargate: Setup And Maintenance AWS Fargate Vs. AWS Lambda: Development AWS Lambda Vs. AWS Fargate: Performance AWS Fargate Vs. AWS Lambda: Monitoring AWS Fargate Vs. AWS Lambda: Security AWS Fargate Vs. AWS Lambda: Use Cases How To Measure, Monitor, And Control AWS Lambda And Fargate Costs

Things are changing. Technology differences between serverless and container-based systems are rapidly blurring.

In 2020, Amazon Web Services (AWS) enabled AWS Lambda to package and deploy functions as container images, instead of bundling all of a function’s code and dependencies in a .zip file. Today, more organizations are increasingly deploying Lambda functions as Docker container images.

These companies want to reap the benefits of serverless computing, containers, and container orchestration. Thus, while AWS Lambda and AWS Fargate are distinct serverless solutions, more companies are using functions (Lambda) with containers, while others want more control over runtime environments using Fargate. 

This guide will make sense of this shift by comparing AWS Fargate vs. Lambda in more detail, taking multiple aspects into account, such as performance, security, and pricing.

Table of Contents

What Is AWS Fargate?

The AWS Fargate service provides a way to run containerized apps on the AWS public cloud with minimal infrastructure management. 

Fargate is a serverless compute solution. So it enables you to focus on container-level tasks, such as setting access controls and resource parameters, instead of more time-consuming tasks, like provisioning, setting up, updating, securing, and scaling clusters of Elastic Compute Cloud (EC2) servers or virtual machines.

AWS Fargate

Credit: Define container parameters with Fargate – TechTarget

Here’s how running containers in AWS with Elastic Compute Cloud (EC2) instances works:

Without Fargate

Now, here’s how AWS Fargate introduces serverless computing into container management in AWS:

With Fargate

From the image, you can tell Fargate abstracts away many of the tasks you’d otherwise need to handle manually.      

You don’t need to choose the right server types, manually scale instances, or patch many issues. AWS handles that on your behalf. Your primary focus is optimizing your code for optimal service delivery. This increases productivity, eases management, and optimizes operational costs.

All this also makes Fargate primarily a Container-as-a-Service (CaaS) offering. It works as an operational mode in Amazon Elastic Container Service (ECS) for Docker-based containers. 

Fargate also works seamlessly with the Elastic Kubernetes Service (Amazon EKS) for Kubernetes-based containers. Each EKS pod or ECS task runs on its own isolated, dedicated runtime environment, further securing them.

The Cloud Cost Playbook

What Is AWS Lambda?

With AWS Lambda, you can run code as functions without managing underlying AWS infrastructure. Lambda is an event-driven compute service, meaning it works by automatically executing tasks in response to compute event triggers. 

A Lambda function is a small program that performs a specific task. It executes when specific events occur in other AWS services, such as when an object is added in an Amazon S3 bucket. Some call this Function-as-a-Service (FaaS), although the Lambda ecosystem goes beyond that. 

Each function runs in an isolated environment with its own file system view and resources. Also, the FaaS approach lets your cloud provider manage most infrastructure tasks compared to CaaS. Check this out:

AWS Lambda

Once you write code (6 languages supported) and upload it, AWS Lambda manages most other tasks necessary for running the containerized app, such as booking a cloud provider’s server resources, patching security issues, and scaling compute resources. 

Here are more comparisons between Lambda and Fargate. 

AWS Lambda Vs. AWS Fargate: Cost

At CloudZero, we treat cost as a first-class metric, so we’ll start with comparing Lambda vs. Fargate pricing. Both services use a pay-as-you-go model, where you pay for only the resources you use — not idle capacity.

Also, note that Fargate and Lambda use entirely different billing models, so it’s tricky to compare them side-by-side — but we’ll do our best.

AWS Lambda charges you per invocation and duration of each invocation, whereas AWS Fargate pricing is based on the resources and region your containerized applications use per second. But there’s more.

AWS Lambda pricing

Lambda pricing does not charge by server units. Instead, Lambda billing is based on: 

  • Number of requests AWS served your functions, and;
  • The time it takes your functions to execute your code (duration)

Lambda will count a request every time it begins executing in response to an invoke call or event notification trigger. It then calculates the duration between the time your Lambda function (or code) starts to execute and when it ends or returns rounded off to the nearest 1 millisecond.    

Billing occurs in 1-millisecond increments. The actual price per duration depends on how much memory you allocate.

AWS Lambda Pricing

Credit: AWS Lambda pricing calculator

With Lambda, you can choose how much memory your function needs using the AWS Lambda resource model. Lambda will automatically assign your function a corresponding amount of CPU and other resources. This happens each time you change your memory configuration. 

For Provisioned Concurrency, Lambda counts: 

  • The amount of concurrency you configure, and
  • The duration you configure it

Enabling Provisioned Concurrency for your functions will charge you for responses and duration as well. How much you pay per request and duration depends on your region/location, although most regions have the same rate.

One more thing. Lambda functions that run on Graviton2 processors using AWS’ Arm architecture can save you up to 34% costs compared to X86-based architecture processors when running workloads such as data and media processing, web, and mobile backends.  

Want to learn more about AWS Lambda billing, including examples and calculations in one place? Check out our Lambda pricing guide here.  

AWS Fargate pricing

Fargate prices are per second with no upfront charge. AWS Fargate will bill you based on the amount of vCPU, RAM, OS, CPU architecture, and storage that your containerized apps consume while running on EKS or ECS. 

For now, you’ll want to confirm the specifics for your setup. For example, as of this writing, Windows OS, storage resources, and Arm CPU architecture are only available through the Amazon ECS implementation. 

Fargate calculates resource usage from the time you start downloading a container image until the ECS task or EKS pod ends. It then rounds off the cost to the nearest second. Also note that there’s a one-minute minimum charge (15 minutes minimum for Windows containers).

Something else. AWS Fargate pricing also varies by region, as do most other services on the AWS public cloud. For example, the cost per vCPU (Linux or X86) and GB per hour in US East (Northern Virginia) is $0.04048 and $0.004445, respectively.

vCPU per hour

Compare that to $0.04456 per vCPU per hour (Linux or X86) and $0.004865 per GB per hour in Canada (Central).

Additional costs apply for data transfers. It also costs extra to use other AWS services with Fargate, like monitoring Fargate with Amazon CloudWatch Logs.   

However, Fargate lets you use AWS Savings Plans (save up to 50% off Fargate On-Demand pricing) and AWS Fargate Spot (save up to 72%). 

If you want to learn more about AWS Fargate pricing, we have a guide on how much Fargate really costs here

Key takeaway: It is tempting to compare Lambda and Fargate pricing head-to-head. But that might not be the best way to go about it. To find out which service best suits your workload requirements and budget, we recommend you review the remaining comparison points below.

AWS Lambda Vs. AWS Fargate: Setup And Maintenance

With Fargate, you package your app in containers, configure the Operating System, vCPU, RAM parameters, networking, and Identity Access Management policies, then launch it. 

Fargate enables you to run ECS tasks and services using the Fargate deployment type or a Fargate capacity provider. AWS handles the rest, including allocating a base CPU and RAM for running your containers. 

Lambda hosts and runs your code on a highly available computing infrastructure. With Lambda, you only manage the application code and functions. AWS handles all else, including hardware, virtualization, and runtime. Those tasks also include server scaling up or down, performing OS maintenance, provisioning RAM and vCPU capacity, and monitoring logs.

You can just write, deploy, and run your code as functions with Lambda, which is the closest thing to serverless computing.

Key takeaway: Overall, AWS Lambda requires much less work to set up and run than AWS Fargate. However, Fargate hands you more control over your container runtime than Lambda.    

AWS Fargate Vs. AWS Lambda: Development

AWS Lambda lets you write, upload, and deploy code for virtually any app or backend service. You’ll need to write your code in Node.js, Python, Ruby, Java, Go, or C#. Alternatively, code compilers, like Maven and Gradle, or packages, can also help you build functions in Lambda.

You can also deploy Docker images with Lambda.

In addition, you can use other programming languages in Lambda by implementing a custom runtime. There is a runtime interface that handles invocation events and responses in Lambda’s execution environment. You’ll be able to deploy a custom runtime along with your function code — or as a compute layer.

With AWS Fargate, you get a serverless compute layer for containers that works as an operational mode in Amazon EKS (Kubernetes based containers) or in ECS (Docker based containers).

Fargate also supports various runtime environments and you have more control over compute capacity allocation when you register your containers with ECS. With Lambda, you are limited to 250MB deployment package size when uploaded to S3 or 10GB when using container images, and 10GB available disk space.

Another thing. To use Fargate with ECS, you must define tasks, which are text files in JSON format, to define your containers. Fargate lets you define up to 10 containers. These definitions empower you to configure your app’s parameters, including OS options (Amazon Linux 2 or Windows 2019 or 2022), the containers to use, the ports to open, and the amount of data to use for each container.

Key takeaway: With Fargate and Lambda, you don’t have to choose the right server types, manually scale instances, or patch many issues in development or production. But if you need more control over your setup, AWS Fargate affords you that compared to AWS Lambda.

AWS Lambda Vs. AWS Fargate: Performance

Prior to April 2022, AWS Fargate deployments took five minutes or more, while AWS Lambda deployments took seconds. In addition, scaling up resources took longer, especially when requests spiked suddenly.

Fargate can now scale up to 500 tasks per service within two minutes when you use ECS service scheduler to handle long-running apps. Previously, it would have taken 15 minutes to do that at steady state.

Lambda VS Fargate Performance

Credit: AWS Fargate task launch rate

In addition, Fargate now supports bursting up to 100 On-Demand or Spot tasks using ECS RunTask API for periodic or onetime batch jobs. This means you can launch tasks at a sustainable 20 tasks per second rate, which is 20X faster than in 2021 and earlier (60 to 90 seconds).

However, because of other factors, like load balancing and health monitoring, Fargate may take a little longer to launch and scale tasks:

Table

Even though Fargate still takes longer to start up than Lambda, it is still faster than before and ECS. Mostly, this is due to Fargate’s need to wait for the underlying ECS clusters to wake up.

AWS Lambda automatically spins up storage and compute resources when a function is called. Besides scaling from 0 to 1000 quickly, Lambda can also scale back to 0 just as fast. This makes Lambda ideal for handling unpredictable traffic spikes or requests.

Fargate does not natively scale to zero, although you can shut it down to save costs. Not scaling to zero means Fargate remains warm, minimizing cold start-induced latencies. But since Fargate scales capacity in a stair-step process, Lambda is often faster in this regard.

Also, Fargate does not support GPUs or tasks that require more than 10 GB of disk storage per container, although this is still far more than Lambda’s 512 MB.

Lambda, however, has no maximum concurrency limits. Although, by default, it is set (by AWS) to 1,000 (you can request more by making a service limit change request to AWS).

After stopping, Lambda functions often suffer cold starts (up to 5 seconds), which may be a bit of a concern for latency-sensitive tasks but negligible for many other tasks. There are various ways to counter the latency, and once warmed up, the issue becomes negligible as the system becomes more efficient.

There is one more thing. The memory limit for a Lambda function is 3GB. AWS does not allow you to select CPU capacity either. Rather, it assigns CPU capacity based on RAM selection. Contrary, Fargate provides a maximum of 30 GB of RAM and 4 vCPUs for all applications.

Key takeaway: AWS has improved both Lambda and Fargate over the years. You may need to spend more time tuning Fargate to start up and scale as quickly or nearly as rapidly as Lambda, despite both having trade-offs. But once Fargate is running, it doesn’t experience latency and offers a more reliable option than Lambda for long-running apps.

AWS Fargate Vs. AWS Lambda: Monitoring

AWS Lambda provides out-of-the-box setup for monitoring logs, metrics, traces, alarms and dashboards. The service automatically sends monitoring metrics to AWS CloudWatch for visualization and reporting.

Monitoring

AWS Lambda monitoring with CloudWatch

Lambda monitoring includes graphs on invocations, min/average/max duration that function code spends processing an event, percentage of successful and errored invocations, times an invocation failed due to concurrency limits (throttles), iteratorAge, number of concurrent executions, and async delivery failures.

Still, it can be challenging to perform granular Lambda monitoring because there isn’t an underlying server on which to run monitoring agents. You may need to output application metrics within functions to boost visibility, and that can incur additional costs both in terms of data transfer and execution time. But you can leverage plenty of tools like Thundra, SumoLogic, and AWS X-Ray for that.

For AWS Fargate monitoring, you can still forward monitoring metrics to Amazon CloudWatch and AWS App Mesh.

Using CloudWatch Container Insights, you can collect, aggregate, and summarize metrics and log data from your AWS ECS and AWS EKS apps. App Mesh abstracts monitoring and routing. This eliminates the need to keep updating the application code. With App Mesh, each service exports monitoring data and applies logic to support consistent exchanges across your application.

Fargate also provides CloudWatch utilization metrics corresponding to AWS service quotas for Fargate On-Demand consumption. You can view your consumption on a graph through the Service Quotas console. You can also set alarms to notify you when your usage is nearing a service quota.

Ultimately, most monitoring tools that work with Amazon ECS will support AWS Fargate as well. In addition, you can use third-party tools like Instana, DataDog, and CloudZero for more granular Fargate monitoring.

Key takeaway: While AWS Lambda automatically pushes logs to CloudWatch, you may need to configure AWS Fargate manually to do the same, including setting up resource usage alarms and dashboards.

AWS Fargate Vs. AWS Lambda: Security

Lambda and Fargate abstract most infrastructure responsibilities away. But security remains an area where AWS encourages shared responsibility. Both services are inherently secure, but how you set up and execute Identity Access Management (IAM) roles in Lambda vs Fargate is the notable difference here.

Lambda allows you to set up IAM roles for each function or service. With AWS IAM modules, only allowed users can access functions. In addition, each function runs in an isolated environment.

In Fargate, security permissions are tied to containers or pods where tasks run. Each Fargate task runs in its own, isolated compute environment, sharing no underlying resources such as CPU/memory, kernel, or elastic network interface with other tasks.

For app security with Fargate, you can integrate AWS Fargate with AWS Secret Manager or AWS Systems Manager Parameter Store for pulling the credentials. You’ll be able to expose the secrets as environment variables in your container.

Key takeaway: Lambda and Fargate both offer built-in security. You still need to do your part to secure your functions and containers. This is especially true for Fargate because it gives you more control, which can increase security misconfiguration. Tools like Sysdig can help you secure your Fargate container deployments from source to run.

AWS Fargate Vs. AWS Lambda: Use Cases

With time, Fargate and Lambda have become increasingly capable of handling similar workloads. But, as you’ve concluded by now, each is stronger in certain areas than the other.

With Lambda, you get seamless, speedy, and automated scaling, a fully managed serverless solution, out-of-the-box logs monitoring, and a compute solution for temporary tasks, among other Lambda use cases. Yet Lambda’s cold start issue might make it unsuitable for latency-sensitive tasks.

With Fargate, you can run long-running containerized tasks, choose your runtime environment, and experience fewer limitations over vCPU, RAM, and ephemeral storage usage. That, in exchange for registering and updating containers in Amazon ECS, configuring Fargate resources, and monitoring them yourself.

Although ECS offers maximum configurability, it is also the most complex to implement. At the other end of that spectrum is AWS Lambda, a full-fledged serverless computing service (nearly no management complexity, but offers minimal control). AWS Fargate sits somewhere in the middle.

Key takeaway: Compared to Lambda, Fargate offers more control and lower costs while AWS does most of the heavy lifting for you.

How To Measure, Monitor, And Control AWS Lambda And Fargate Costs

Using AWS Lambda or AWS Fargate not only relieves you of managing clusters of servers, but can also lower your AWS costs compared to using Amazon ECS. The problem with serverless infrastructure is that it’s often difficult to visualize, analyze, and optimize costs.

It’s critical that you have a platform that can accurately collect, analyze, and report serverless resource usage metrics. However, most cost management tools aren’t up to the job. Most require you to continually update cost allocation tags to keep up.

With CloudZero, you can accurately track AWS Lambda or AWS Fargate costs without tagging. We’ve also built CloudZero on serverless infrastructure as more of an observability tool than a mere cost tool. This provides you with continuous cost insight into metrics you care about; cost per customer, cost per software feature, cost per team, cost per product, and more.

Transform your spend with dimensions

You can also track your containerized and non-containerized costs down to the hour, cluster, namespace, and pod.

Kubernetes Complete Cost

CloudZero maps costs to the people, products, and processes that generate your costs. You can then pinpoint where to optimize costs to improve your margins. CloudZero also monitors your Fargate and Lambda deployments in real-time and notifies you of cost anomalies to prevent overspending.

But don’t just take our word for it. to seeCloudZero in action!

The Cloud Cost Playbook

The step-by-step guide to cost maturity

The Cloud Cost Playbook cover