AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?
Tags: aws, cloud, devops, serverless
Published: 2023-09-21 11:41:25

---
title: AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?
published: true
tags: AWS, Cloud, DevOps, Serverless
canonical_url: https://firstfinger.in/aws-lambda-vs-lambda-edge/
---

> ✅ To stay up-to-date, be sure to subscribe to our [weekly newsletter](https://short.firstfinger.in/newsletter) or join our [WhatsApp Channel](https://short.firstfinger.in/whatsapp-invite). We appreciate your interest 😀!

---


![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/AWS-Lambda-vs-Lambda@Edge.jpg)

If you are familiar with cloud computing, you may have heard of AWS Lambda, a service that lets you run code without provisioning or managing servers. **AWS Lambda is a popular choice for building serverless applications** , as it automatically scales, charges only for the compute time you consume, and supports a variety of languages and frameworks.

But did you know that AWS also offers another service called Lambda@Edge, which allows you to run Lambda functions at the edge locations of the AWS network? [**_Lambda@Edge is a feature of Amazon CloudFront, a global content delivery network (CDN) that speeds up the delivery of your web content to your users._**](https://dev.to/anurag_vishwakarma/optimizing-content-delivery-with-aws-lambdaedge-vs-cloudfront-30fi-temp-slug-5463732)

In this blog post, we will explore the differences between Lambda@Edge and AWS Lambda, and how you can use them to enhance your web applications.

 ![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/45551.png)

## What is AWS Lambda?

[**AWS Lambda**](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) **is a computing service that allows [running code](https://dev.to/firstfingerin/monorepos-vs-microrepos-which-is-better-3ihe) without server management.** You only pay for compute time, not idle time. With Lambda, you upload your code and Lambda takes care of everything required to [run and scale](https://dev.to/firstfingerin/top-container-orchestration-platforms-kubernetes-vs-docker-swarm-56pd) your code with high availability.

![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/AWS-Lambda-Tutorial-Getting-Started-with-Serverless-Computing--KodeKloud-00-04-41.png)
_AWS Lambda | Image Credit: KodeKloud_

AWS Lambda runs your code in one of the 24 AWS regions around the world. You can choose which region to deploy your [Lambda function](https://www.freecodecamp.org/news/python-lambda-function-explained), and it will be invoked whenever an event triggers it. For example, you can use AWS Lambda to process data from Amazon S3, DynamoDB, or [API Gateway](https://dev.to/anurag_vishwakarma/what-makes-load-balancer-vs-api-gateway-different-and-use-cases--27bi-temp-slug-1230060).

> **_Some key characteristics of AWS Lambda:_**

### #1. Fully Managed Service

- Lambda completely abstracts away everything about servers so you don't have to manage any infrastructure.
- Simply [upload your code](https://firstfinger.in/file-transfer-project-javascript-html-css-firebase/), and Lambda takes care of all the necessary processes to run and scale it.

### #2. Event-Driven

- Lambda functions are triggered by events from various [AWS services](https://dev.to/anurag_vishwakarma/how-to-create-kubernetes-clusters-on-aws-4jba-temp-slug-7135100) or your own applications.
- You can set a Lambda function to be invoked when an object is uploaded to S3, a table is updated in DynamoDB, an API call is made, etc.

### #3. Scales Automatically

- Lambda functions [scale automatically based on demand](https://dev.to/anurag_vishwakarma/how-to-scale-your-database-strategies-performance-59bl).
- As traffic increases, Lambda provisions [additional capacity to handle it](https://dev.to/anurag_vishwakarma/bare-metal-vs-virtual-machines-vs-containers-the-differences-jkh). When traffic decreases, excess capacity is removed.

### #4. Pay Per Request

- With Lambda, you only pay for the compute time you use.
- There are no charges when your code is not running.
- You are charged based on the number of requests and compute time consumed.

### #5. Quick Start

- It's easy to start with Lambda - just upload your code as a .zip file.
- Lambda supports code written in Node.js, Python, Java, C# and more.

💡

Lambda provides a simple, automated and scalable way to run your code in response to events without managing any servers.

* * *

 ![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/45542.png)

## What is Lambda@Edge?

[**Lambda@Edge**](https://aws.amazon.com/lambda/edge/) **is an extension of AWS Lambda that allows you to execute functions at AWS edge locations globally.** You can use it to customize content delivered through Amazon CloudFront.

![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/What-is-Lamdba@Edge-and-How-is-it-Different-from-AWS-Lambda-00-03-38Compress.webp)
_CloudFront with Lambda@Edge | Image Credit: StormIT_

[**Lambda@Edge functions execute logic globally in response to CloudFront events like viewer requests and origin responses.**](https://dev.to/anurag_vishwakarma/optimizing-content-delivery-with-aws-lambdaedge-vs-cloudfront-30fi-temp-slug-5463732) This allows you to run code at edge locations near users instead of a centralized region.

Specifically, Lambda@Edge runs your code across over 200 cities in 70 countries using AWS edge locations. You can leverage Lambda@Edge to customize CloudFront content based on factors like user location and device. Potential use cases include resizing images, rewriting URLs, and [injecting HTTP headers before delivery.](https://dev.to/anurag_vishwakarma/what-are-hsts-and-csp-security-headers-and-the-difference-between-them-5bff-temp-slug-4763402)

> **_Some key aspects of Lambda@Edge:_**

### #1. Deployed Globally with Low Latency

- Lambda@Edge functions are deployed globally to CloudFront edge locations.
- This puts the code physically closer to users to reduce latency.

### #2. Integrated with CloudFront

- Lambda@Edge functions are triggered by CloudFront events like viewer requests.
- To use Lambda@Edge, you must use CloudFront as the content delivery [network](https://firstfinger.in/vpn-vs-zero-trust-network-remote-access/).

### #3. Customize Content Delivery

- Lambda@Edge can be used to dynamically customize content served through CloudFront.
- For example, resize images, throttle requests, or reroute based on device type.

### #4. Pay Per Request

- Like AWS Lambda, you only pay for compute time used by Lambda@Edge functions.
- There is no charge when the code is not running.

💡

Lambda@Edge allows you to execute code globally in AWS edge locations in response to CloudFront events to customize content delivery.

* * *

 ![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/11292.png)

## Key Differences between Lambda and Lambda@Edge

Now that we've provided an overview of both services, let's look at some of the key differences between AWS Lambda and Lambda@Edge:

| | Lambda | Lambda@Edge |
| --- | --- | --- |
| Scope | Regional | Global |
| Purpose | General computing | CloudFront computing |
| Features | More features | Limited features |
| Pricing | Pay per use | Monthly fee + usage |

### #1. Geographic Scope

The main difference is that **Lambda is a regional service while Lambda@Edge is global**.

- AWS Lambda functions run in specific AWS regions you choose (like us-east-1).
- To distribute Lambda globally, you must deploy it to multiple regions.
- Lambda@Edge functions run globally in AWS edge locations near users. You don't have to deploy to each region manually.

### #2. Integration

**Lambda can integrate with many AWS services while Lambda@Edge only works with CloudFront**.

- Lambda can be triggered by events from S3, DynamoDB, API Gateway, and many other services.
- Lambda@Edge is specifically designed to work with CloudFront, running in response to CloudFront events.

### #3. Use Cases

**The use cases are different for each service**.

- Lambda is often used for general backend processing like data transformation, notifications, etc.
- Lambda@Edge is primarily used for optimizing content delivery from CloudFront like [dynamic caching](https://dev.to/anurag_vishwakarma/why-redis-is-so-fast-it-will-blow-your-mind-2b6-temp-slug-6796485), modifying response headers, and customizing content.

### #4. Execution Environment

**The execution environments are different**.

- Lambda provides a generic compute environment where you bring your own dependencies.
- Lambda@Edge has a limited environment with specific supported languages and [OS versions](https://firstfinger.in/why-macbook-is-better-than-windows-laptops/).

### #5. Features

**Some Lambda features are not supported in Lambda@Edge** like environment variables, VPC access, Lambda layers, etc.

### #6. Pricing

- **Lambda pricing** is based on requests and compute time consumed.
- **Lambda@Edge pricing** has an additional fixed monthly fee per CloudFront distribution, plus request and compute charges.

* * *

 ![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/314.png)

## Lambda@Edge has some limitations compared to AWS Lambda

![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://d1tcczg8b21j1t.cloudfront.net/strapi-assets/lambda_at_edge8_5d7aea98ea.png)
_Lambda@edge limitations | Image Credit: StormIT_

- **Lambda@Edge functions have a maximum execution time of 5 seconds** for viewer request and response events, and **30 seconds** for origin request and response events. AWS Lambda functions have a maximum execution time of 15 minutes.
- **Lambda@Edge functions have a maximum memory size of 128 MB** for viewer request and response events, and **10 GB** for origin request and response events. AWS Lambda functions have a maximum memory size of 10 GB.
- **Lambda@Edge functions have a maximum package size of 1 MB** for viewer request and response events, and **50 MB** for origin request and response events. AWS Lambda functions have a maximum package size of 50 MB for ZIP files and 10 GB for images.
- **Lambda@Edge functions cannot access other AWS services or resources directly.** They can only access the HTTP request and response objects. AWS Lambda functions can access other AWS services or resources using the AWS SDKs or APIs.
- **Lambda@Edge functions cannot use environment variables or layers.** AWS Lambda functions can use environment variables and layers to store configuration data or reuse code.
- **Lambda@Edge functions cannot be tested or invoked manually** in the AWS console. They can only be tested by sending requests to your CloudFront distribution. AWS Lambda functions can be tested or invoked manually in the AWS console or using the AWS CLI or SDKs.

* * *

 ![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/1725.png)

## When to Use Lambda@Edge vs. Lambda?

### Guidelines on when to use each service:

### 🟠 Use Cases for Lambda@Edge

Lambda@Edge is ideal when you need to:

![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/What-is-Lamdba@Edge-and-How-is-it-Different-from-AWS-Lambda-00-07-37Compress.webp)
_Lambda@Edge Use Case | Image Credit: StormIT_

- Customize or manipulate content delivered through **CloudFront** globally
- Run code closer to users by leveraging **CloudFront edge locations**
- Execute logic in response to **CloudFront events** like viewer requests
- Perform processing on the **edge** before reaching the origins
- Implement use cases like A/B testing, user-based redirection, etc.

### 🟡 Use Cases for AWS Lambda

Lambda is a better choice when you need:

![AWS Lambda vs. Lambda@Edge: Which Serverless Service Should You Use?](https://firstfinger.in/content/images/2023/09/AWS-Lambda-Tutorial-Getting-Started-with-Serverless-Computing--KodeKloud-00-06-22Compress.webp)
_Lambda Use Case | File Resize Application | Image Credit: KodeKloud_

- A **general purpose** compute service to run code
- Integration with multiple **AWS services** like S3, DynamoDB etc.
- Access to networks, security groups, and **VPC resources**
- Additional features like **environment variables, layers** etc.
- A **regional service** located close to other AWS resources
- Use cases like data processing, notifications, ETL, backups, etc.

😈

Use **Lambda@Edge** when you specifically need global edge processing with CloudFront. Use **AWS Lambda** when you need general computing that interacts with multiple AWS services.

* * *

## Quick Summary

- **AWS Lambda** is a general, regional compute service that runs code in response to events from various sources.
- **Lambda@Edge** runs code globally at CloudFront edge locations in response to CloudFront events to customize content delivery.
- **Lambda** can be triggered by many AWS services. **Lambda@Edge** only works with CloudFront.
- **Lambda** has more features while **Lambda@Edge** has constraints.
- **Lambda** is pay-per-use. **Lambda@Edge** has a monthly fee plus usage charges.
- Use **Lambda@Edge** for global edge processing with CloudFront.
- Use **AWS Lambda** for general serverless computing across multiple services.

## Conclusion

In conclusion, AWS Lambda and Lambda@Edge help run code without managing servers but are suited for different use cases.

**Lambda@Edge** is a feature of **CloudFront** that lets you run code at the edge locations of the AWS network, while **Lambda** lets you run code in one of the **AWS regions**. Lambda@Edge is ideal for customizing web content and improving performance, while Lambda is ideal for processing data and integrating with other AWS services.

* * *

## FAQs

#### What is AWS Lambda?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

AWS Lambda is a service that executes code in response to events and automatically handles the computing resources. You simply upload your code and Lambda handles everything required to run and scale it with high availability.

#### What is Lambda@Edge?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

Lambda@Edge lets you run Lambda functions globally at Edge locations to customize content delivered through Amazon CloudFront. This allows you to execute code closer to users to reduce latency.

#### Can I access VPC resources from Lambda@Edge?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

No, Lambda@Edge does not provide access to VPC resources. It runs in the CloudFront network and can only interact with CloudFront. AWS Lambda does provide VPC access.

#### What languages can I use with Lambda@Edge?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

Currently, Node.js and Python are supported for Lambda@Edge. AWS Lambda supports a wider range of languages including Java, C#, Go, and Ruby.

#### Is Lambda@Edge available globally?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

Yes, Lambda@Edge deploys your functions globally across all CloudFront edge locations automatically so they run closer to your users for reduced latency.

#### Can I use Lambda@Edge and AWS Lambda together?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

Yes, you can. Lambda@Edge can be used in conjunction with AWS Lambda to provide additional functionality at the edge for your applications.

#### Are Lambda@Edge functions limited in terms of runtime?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

Lambda@Edge functions have a maximum execution time of 5 seconds, which is shorter than AWS Lambda's configurable runtime limits.

#### Can I deploy AWS Lambda functions globally like Lambda@Edge?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

AWS Lambda functions are deployed regionally, so you can choose the region that best suits your needs, but they are not automatically replicated globally like Lambda@Edge.

#### Is there a difference in pricing between Lambda@Edge and AWS Lambda?
<button>
                    <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
                        <path d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"></path>
                    </svg>
                </button>

Yes, pricing for Lambda@Edge is based on the number of requests and the duration of function execution at edge locations, while AWS Lambda pricing depends on factors such as function execution time and memory usage.


> ✅ To stay up-to-date, be sure to subscribe to our [weekly newsletter](https://short.firstfinger.in/newsletter) or join our [WhatsApp Channel](https://short.firstfinger.in/whatsapp-invite). We appreciate your interest 😀!