- Newest
- Most votes
- Most comments
The latency increase you're experiencing when switching from CloudFront Functions to Lambda@Edge is expected and aligns with the architectural differences between these two edge computing options.
CloudFront Functions are designed specifically for lightweight, latency-sensitive use cases. They execute directly at the CloudFront edge locations, closer to your users, and are optimized for tasks like HTTP header manipulation, URL rewrites, and basic authorization checks like JWT validation.
Lambda@Edge, on the other hand, runs in regional edge caches (usually in the AWS Region closest to the CloudFront edge location that received the request), not at the edge locations themselves. This introduces additional network hops and processing overhead. Lambda@Edge functions must complete before CloudFront can continue processing the request, which directly impacts the overall latency.
The 30-50ms latency increase you're seeing is consistent with what you might expect when moving from CloudFront Functions to Lambda@Edge. This is the trade-off for gaining the additional capabilities that Lambda@Edge provides, such as the ability to make network calls (like fetching from JWKS endpoints), using more complex logic, and having access to more runtime memory and execution time.
If you need the additional capabilities of Lambda@Edge for fetching JWKS endpoints, you'll need to accept this latency trade-off. However, if latency is critical for your application, you might consider alternative approaches, such as periodically pre-fetching and caching the JWKS data elsewhere, then making it available to your CloudFront Function through configuration or other means.
Remember that Lambda@Edge is priced at approximately six times the cost of CloudFront Functions, so there are both performance and cost implications to consider in your decision.
Sources
CloudFront events that can trigger a Lambda@Edge function - Amazon CloudFront
Architecture - Amazon CloudFront for Media
Yes, that delta is normal. CloudFront Functions run natively on the global edge locations—those are micro‑VMs executing inline with the request pipeline. Lambda@Edge runs from regional edge caches, which sit one tier deeper in the network. Each invocation involves a hop from the edge location to the regional edge and back, plus the Lambda initialization and runtime overhead. That routinely adds tens of milliseconds even for warm executions. Cold starts or larger payloads widen the gap further. If JWT validation is the only logic you need, keep it in CloudFront Functions since they were built for sub‑millisecond header inspection and lightweight token checks. —Taz
answered 9 months ago
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 7 months ago

Are CloudFront functions capable of HMAC crypto to actually validate JWT signature though? If not, they can just be simply forged right?