
CloudFront Functions and Lambda@Edge both run code in the Amazon CloudFront delivery path, but they are designed for different kinds of work. CloudFront Functions targets extremely frequent, short-lived operations that do not need network access. Lambda@Edge supports more complex logic, including origin events, outbound network calls, and access to request bodies.
The right choice is not simply the service with more features. You need to determine when the code must run, whether it must contact another service, whether it needs the request body, and how much execution time and memory it requires. Putting a basic URL rewrite in Lambda@Edge can add unnecessary cost and operational work. Putting logic that must query an identity provider in CloudFront Functions will not work because CloudFront Functions cannot make network calls.
CloudFront Functions vs Lambda@Edge at a Glance
| Category | CloudFront Functions | Lambda@Edge |
|---|---|---|
| Supported events | Viewer request and viewer response | Viewer request, viewer response, origin request, and origin response |
| Execution location | CloudFront edge locations; designed for submillisecond processing | AWS Regions closer to viewers; offers a fuller compute environment |
| Runtime | CloudFront JavaScript runtime | Supported Node.js and Python runtimes |
| Maximum duration | 1 millisecond | 5 seconds for viewer events; 30 seconds for origin events |
| Memory | 2 MB | 128 MB for viewer events; configurable up to 10,240 MB for origin events |
| Code or package size | 10 KB | 1 MB for viewer events; 50 MB for origin events |
| Network access | Not available | Available |
| Request body access | Not available | Available with truncation limits: 40 KB for viewer request and 1 MB for origin request |
| Data access | CloudFront KeyValueStore with JavaScript runtime 2.0 | Can contact supported remote services over the network |
| Common uses | Redirects, header changes, cache-key normalization, and lightweight authorization | Origin selection, network calls, request-body processing, and more complex authorization |
A practical rule: start with CloudFront Functions when the operation can finish within 1 millisecond using only the request, response, and a small amount of key-value data. Evaluate Lambda@Edge when you need network access, request bodies, origin events, or more compute resources.
When Should You Use CloudFront Functions?
CloudFront Functions runs at the viewer-facing stages of a CloudFront request. It can modify the URI, query string, cookies, and headers before CloudFront looks up an object in the cache. It can also adjust response headers before a response goes back to the viewer. Its location, short startup path, and low invocation price make it suitable for small, deterministic operations that run across very large request volumes.
URL Redirects and Rewrites
Typical examples include redirecting legacy paths, normalizing uppercase and lowercase URLs, adding or removing trailing slashes, and mapping language entry points to the appropriate directory. If the rule can be decided from the current request without querying a database or API, CloudFront Functions is usually the first option to evaluate.
Request Normalization and Cache Efficiency
The same object can create multiple cache keys because of irrelevant query parameters, cookies, or headers. A CloudFront Function can remove tracking parameters, normalize parameter order, or standardize header values before the cache lookup. This requires care: never discard a value that genuinely changes the response, or CloudFront could serve the wrong variant to a viewer.
Lightweight Access Control
CloudFront Functions can support simple token checks, signature validation, country-based routing, and device-based routing when all required information is locally available. CloudFront KeyValueStore can provide a small set of frequently read configuration data. If authorization requires a real-time call to an identity provider, database, revocation list, or another API, use Lambda@Edge, an origin-side service, or another suitable architecture.
When Should You Use Lambda@Edge?
Lambda@Edge supports the viewer events as well as the stages immediately before CloudFront sends a request to an origin and after CloudFront receives the origin response. It offers longer execution time, more memory, and network access. These capabilities cover workloads that CloudFront Functions cannot perform, but they also make deployment, logging, troubleshooting, and billing more involved.
Dynamic Origin Selection
During an origin request event, Lambda@Edge can modify the origin request according to the path, headers, cookies, or application rules. For example, it can route different content categories to different origins or apply custom multi-origin logic. These functions should include explicit timeout and failure behavior so that edge logic does not become a new point of failure.
Authorization That Requires Network Calls
If each request must query an authorization service, retrieve remote configuration, or call another API, CloudFront Functions is not an option because it has no network access. Lambda@Edge can make outbound calls, but the dependency's latency directly affects the viewer and can increase duration-based charges. Cache reusable validation results where appropriate, and define how the application behaves when the remote service is slow or unavailable.
Reading a Request Body
Lambda@Edge can include a request body in the event, subject to size limits. The body is truncated at 40 KB for viewer request events and at 1 MB for origin request events. This can work for small forms or limited payload inspection, but it is not a replacement for processing large uploads at the edge. Test Base64 handling, content length, and origin behavior whenever the function reads or changes a body.
Deployment and Logging Differences
You can develop, test, and publish a CloudFront Function to the LIVE stage through CloudFront. Its function logs are written to CloudWatch Logs in the US East (N. Virginia) Region, us-east-1. Logging capacity is limited and log delivery can be throttled, so a function should not emit large amounts of business data on every invocation.
A Lambda@Edge function must be created in us-east-1 and published as a numbered version before it is associated with CloudFront. You cannot associate $LATEST or a Lambda alias. AWS then replicates the function to the Regions where it executes. CloudWatch Logs are written in the AWS Region where each replica runs, so troubleshooting a global distribution may require checking multiple Regions rather than only us-east-1.
Lambda@Edge also has restrictions that differ from standard Lambda. It does not support custom environment variables, Lambda layers, VPC access, container images, provisioned concurrency, or arm64. An existing regional Lambda function may therefore require changes before it can be used with Lambda@Edge.
CloudFront Functions and Lambda@Edge Pricing
Under the currently published AWS pricing, CloudFront Functions costs $0.10 per 1 million invocations. Lambda@Edge request pricing is $0.60 per 1 million requests, plus compute charges based on allocated memory and execution duration. Free allowances, CloudFront flat-rate plans, discounts, taxes, and account structure can affect the final bill.
For an illustrative workload of 100 million executions in one month, before free allowances or discounts:
CloudFront Functions: 100 × $0.10, or approximately $10 in invocation charges.
Lambda@Edge: 100 × $0.60, or approximately $60 in request charges, plus memory-and-duration compute charges.
This example only explains the billing structure and is not an AWS or CloudFlew quote. Actual charges are governed by the current purchase page, AWS billing rules, and applicable service terms.
Price should never be separated from technical requirements. CloudFront Functions cannot replace Lambda@Edge when the function must use the network. Conversely, paying Lambda@Edge request and compute charges is usually unnecessary when the only task is removing an irrelevant query parameter. Include logging, remote-service, origin-request, and maintenance costs in the comparison.
Can You Use Both Services Together?
Yes. You can combine both services within one CloudFront distribution by assigning them to compatible, different event phases. AWS does not allow a CloudFront Function and a Lambda@Edge function on the same viewer event for the same cache behavior. One valid design is to normalize the URL with CloudFront Functions at viewer request and then select an origin with Lambda@Edge at origin request.
Keep responsibilities clear when combining them. Store each normalization rule in one place, pass authorization results through explicitly defined headers, and document which fields each phase may change. Otherwise, the same URI may be rewritten multiple times and produce cache or routing behavior that is difficult to reproduce.
Practical Selection Table
| Requirement | Start With | Why |
|---|---|---|
| URL redirects, path rewrites, and header normalization | CloudFront Functions | Lightweight, high-volume logic without network access |
| Remove query parameters or normalize cache-key inputs | CloudFront Functions | Runs before the cache lookup |
| Route requests using a small configuration dataset | CloudFront Functions with KeyValueStore | Avoids a remote call for simple configuration |
| Call an identity service or third-party API | Lambda@Edge | Requires network access |
| Read or modify a small request body | Lambda@Edge | CloudFront Functions cannot access the body |
| Dynamically select an origin before forwarding | Lambda@Edge origin request | CloudFront Functions has no origin events |
| Run heavier computation or use a larger dependency package | Lambda@Edge, or reconsider origin-side processing | Requires more time, memory, and code space |
Pre-Deployment Checklist
Identify the event phase. Must the code run before cache lookup, before the origin request, after the origin response, or just before delivery to the viewer?
List external dependencies. Does it need network access, a request body, a file system, environment variables, or a Lambda layer?
Estimate invocation volume. Viewer functions can run on nearly every request, while origin functions generally run only when CloudFront goes to the origin.
Test cache behavior. Any change to a URI, header, cookie, or query string can affect cache hits and content isolation.
Define failure behavior. If the function fails, times out, or cannot reach an API, should the request be rejected, bypass the logic, or fall back to the origin?
Plan multi-Region troubleshooting. For Lambda@Edge, document log Regions, alarms, version deployment, and rollback procedures.
Protect sensitive data. Do not write complete tokens, cookies, personal data, or secrets to logs.
Frequently Asked Questions
Can CloudFront Functions call an API?
No. CloudFront Functions does not provide network access. If the logic must contact an external API in real time, evaluate Lambda@Edge, an origin application, or another service. For a small, frequently read configuration dataset, consider CloudFront KeyValueStore.
Can Lambda@Edge use environment variables or Lambda layers?
Lambda@Edge does not support custom environment variables or Lambda layers. Reorganize configuration and dependencies around the Lambda@Edge restrictions before deployment, and do not hard-code sensitive secrets into the function.
Which service should handle JWT validation?
CloudFront Functions can be considered when the required key material is safely available in the function or KeyValueStore and verification fits within its strict limits. If validation requires a real-time identity-provider call, token revocation lookup, or user-permission query, Lambda@Edge or a dedicated authorization service is a better fit.
Which option has lower latency?
For an appropriate lightweight operation, CloudFront Functions runs at CloudFront edge locations with submillisecond execution and generally adds less processing overhead. Lambda@Edge provides more capability, but complex logic and network calls can increase latency. Benchmark with production-like requests before making a final decision.
Conclusion
CloudFront Functions is lightweight, fast, and inexpensive per invocation. It is well suited to URL, header, cookie, query-string, and simple access-control operations at viewer events. Lambda@Edge adds origin events, network access, request-body support, longer execution time, and more memory, making it appropriate for origin routing, remote service calls, and more complex application logic.
Start with the smallest implementation that fully meets the requirement. If CloudFront Functions fits within its constraints, you can avoid the additional deployment and troubleshooting overhead of Lambda@Edge. If the requirement clearly involves networking, body access, or origin-stage processing, use Lambda@Edge or reconsider whether the work belongs at the origin. Before launch, estimate costs using real request volume and test caching, security, failure fallback, and logging.
References
AWS CloudFront Developer Guide: Choosing between CloudFront Functions and Lambda@Edge, reviewed August 18, 2026
AWS CloudFront Developer Guide: Restrictions on CloudFront Functions, reviewed August 18, 2026
AWS CloudFront Developer Guide: Restrictions on Lambda@Edge, reviewed August 18, 2026
AWS CloudFront Developer Guide: Lambda@Edge quotas, reviewed August 18, 2026
AWS: Amazon CloudFront Pricing, reviewed August 18, 2026
AWS: Lambda@Edge, reviewed August 18, 2026