amazon-web-servicesamazon-cloudfrontaws-lambda-edge

How to investigate repeated cached lambda at edge requests


I have the following Cloudfront and lambda at edge setup

Visually it would be like this

visual CDN architecture

fig 1. Visual CDN architecture

In my behavior cache settings I have the following set:

Given that cloudfront caches everything per region, and that I do not expect many hits on the CDN at all (5 a day at most), I'd expect only one origin request to be made per day per region, but sometimes I see 2 requests being made hours apart for the same day

Cloudfront monitoring for origin requests

fig 2. Cloudfront monitoring for origin requests

Question stands: Am I misunderstanding how caching works in cloudfront, considering I write Expires end of day header (for april 29th I'd write 2025-04-30 00:00:00 UTC) and this is expected behavior, or is there a misconfiguration somewhere within caching? Are there tools to test caching configurations?


Solution

  • You’re mostly on the right track, but there are a few nuances with how CloudFront handles caching and Lambda@Edge that could explain the behavior you’re seeing.

    What’s happening

    Even if you:

    You can still see multiple origin fetches per day per edge location. This is because:

    Why this can happen

    Your graph from the Lambda@Edge metrics shows multiple low-volume invocations. This likely means:

    This is expected behavior for a low-traffic CDN setup.

    Tips to reduce this

    Tools to debug

    TL;DR:

    CloudFront caching is per edge location, not global. Low traffic across multiple regions can cause multiple origin fetches—even with proper Expires and TTL settings. Use Origin Shield and log tools to better visualize and reduce these edge cache misses.