Backbencher.dev

Disable Cloudfront Cache for Lambda@Edge

Last updated on 14 Dec, 2022

When Cloudfront serves content from Lambda@edge, the response from Lambda@edge is cached. So, when Cloudfront receives a request again, it serves from cache.

In some cases, you might want to disable caching for Lambda@edge. You want all requests to invoke the Lambda@edge function. For that, you need to customize the Cloudfront Behavior that is attched to Lambda@edge function.

Function association

In the image above the Lamba@edge functions are associated with Origin request and Origin response. That will cache the output. Instead, attach the same function to Viewer request and Viewer response. That will make sure that for all viewer requests, the Lambda@edge function is invoked.

--- ○ ---
Joby Joseph
Web Architect