
- Edge locations are globally distributed caching and compute points used by Amazon CloudFront to deliver content with minimal latency. They serve cached objects (for example, static assets and streaming media) as close to the viewer as possible.
- CloudFront Functions and Lambda@Edge let you run custom code at these edge locations so you can inspect or modify requests and responses close to the viewer, reducing round-trips to origins and improving performance for common operations.
- CloudFront Functions
- Executed on CloudFront edge servers.
- Designed specifically for viewer-based events (requests coming from and responses going to the viewer).
- Optimized for extremely low-latency, high-concurrency tasks with a lightweight JavaScript runtime.
- Lambda@Edge
- Also runs at CloudFront edge locations but supports all four CloudFront event types:
viewer-request,origin-request,origin-response, andviewer-response. - Provides a full Lambda runtime (supported runtimes) and greater control over origin-to-viewer flows.
- Also runs at CloudFront edge locations but supports all four CloudFront event types:

Practical guidance
- Event coverage: If your logic only needs to inspect or change the request/response that the viewer sees, prefer CloudFront Functions. If you need to modify or inspect traffic that goes to or comes from your origin, use Lambda@Edge.
- Capabilities: CloudFront Functions are ideal for deterministic, short-running JavaScript snippets (e.g., URL rewriting, header adjustments). Lambda@Edge is for heavier processing, interacting with external APIs, or using the AWS SDK.
- Performance vs. flexibility: Start with CloudFront Functions when possible for lower latency and cost. Move to Lambda@Edge only when CloudFront Functions cannot meet the functional requirements.
- Deployment considerations: CloudFront Functions are attached to behaviors directly and execute at edge locations without version replication concerns. Lambda@Edge requires you to publish versions and associate them with behaviors; changes may take time to propagate to all edge locations.
- CloudFront Function: rewrite request URIs from
/old-path/*to/new-path/*
- Lambda@Edge: add a custom header on viewer request (Node.js Lambda)
Use CloudFront Functions for latency-sensitive viewer events and simple transformations. Choose Lambda@Edge when you need origin-level control, complex processing, or access to the full Lambda runtime and AWS SDKs.
- Choose CloudFront Functions when:
- You need
viewer-requestorviewer-responseonly. - Tasks are small, deterministic, and require the lowest latency.
- You want simple header rewrites, redirects, or cache-key logic.
- You need
- Choose Lambda@Edge when:
- You need
origin-requestororigin-responseevents. - You must call external services, use the AWS SDK, or perform complex transformations.
- You require language/runtime features not available in CloudFront Functions.
- You need
- Amazon CloudFront Functions – Developer Guide
- Lambda@Edge – Developer Guide
- CloudFront distribution behaviors
- Edge locations cache content and provide compute near users for reduced latency.
- CloudFront Functions are the preferred choice for very fast, simple request/response transformations at viewer events.
- Lambda@Edge supports broader event coverage and more complex processing at the edge, but with added latency, cost, and operational overhead.