CloudFront Functions and Lambda@Edge both run code close to CloudFront viewers, but they are designed for different levels of complexity. CloudFront Functions are lightweight and optimized for very low-latency request manipulation. Lambda@Edge supports more complex logic and a broader execution environment, with additional deployment and runtime considerations.
CloudFront Functions: lightweight viewer-side logic
CloudFront Functions are designed for short-running, high-scale operations at CloudFront edge locations. Typical uses include URL rewrites and redirects, header manipulation, request normalization, and simple authorization checks. They execute at viewer-request or viewer-response events and are optimized for very low latency.
Lambda@Edge: more complex edge processing
Lambda@Edge uses AWS Lambda functions replicated to CloudFront edge locations. It supports more complex logic than CloudFront Functions, including access to request bodies in supported event configurations, network calls, and integrations that require the Lambda execution environment. It can run at viewer-request, viewer-response, origin-request, and origin-response events. Deployments have additional requirements, including publishing a numbered Lambda version in US East (N. Virginia), us-east-1, before associating it with a distribution.
Event location comparison
| CloudFront event | CloudFront Functions | Lambda@Edge |
|---|---|---|
| Viewer request | Yes | Yes |
| Viewer response | Yes | Yes |
| Origin request | No | Yes |
| Origin response | No | Yes |
Choose by the requirement
- Simple redirect or URL rewrite at the viewer edge → CloudFront Functions.
- Normalize headers or cookies with extremely low latency → CloudFront Functions.
- Run logic when a request is sent to the origin or a response returns from the origin → Lambda@Edge.
- Need a richer Lambda runtime or more complex processing → Lambda@Edge.
- Need to inspect a request body → Lambda@Edge in a supported event configuration.
Deployment and operational differences
CloudFront Functions are created and associated through the CloudFront function workflow and are designed for fast publication at the edge. Lambda@Edge requires a Lambda function version published in us-east-1 and replicated by CloudFront. Replication and distribution updates can take time. Review current quotas, runtime support, and event restrictions before choosing an implementation.
Exam traps
- CloudFront Functions do not run on origin-request or origin-response events.
- Lambda@Edge supports all four CloudFront trigger points.
- CloudFront Functions are the better fit for simple, ultra-low-latency viewer request/response changes.
- Lambda@Edge is not simply “a faster CloudFront Function”; it supports more complex logic and has additional deployment overhead.
- Lambda@Edge functions must be created in us-east-1 and associated using a numbered version.
Test yourself
Question 1
A website needs to perform a simple URL redirect at the viewer-request event with minimal latency. Which option is the best fit?
- Lambda@Edge origin response
- CloudFront Functions
- Amazon ECS
- AWS Step Functions
Reveal answer
Correct answer: B. CloudFront Functions are optimized for lightweight viewer request/response logic with very low latency.
Question 2
A solution must execute custom logic on an origin-response event after the origin returns content. Which service supports this trigger?
- CloudFront Functions only
- Lambda@Edge
- Amazon Route 53
- AWS WAF only
Reveal answer
Correct answer: B. Lambda@Edge supports origin-request and origin-response events; CloudFront Functions support viewer events only.
Key takeaway
Use CloudFront Functions for simple, ultra-low-latency viewer-side changes. Use Lambda@Edge when the scenario needs origin events or more complex Lambda capabilities. Know the event matrix and the us-east-1 versioned deployment requirement.
Related topics
Amazon CloudFront · AWS Lambda · AWS Edge Locations
Ready for the AWS Solutions Architect Associate (SAA-C03) exam?
Turn what you learned in this topic into exam-ready skills with original, scenario-based practice questions and detailed explanations.
Original practice questions. No dumps. No shortcuts.