- Newest
- Most votes
- Most comments
It's not currently possible to selectively invoke a Lambda@Edge function based on the status code in the response, but it's worth being aware of how caching in CloudFront will impact the number of invocations.
Functions associated with the Origin triggers only run when CloudFront requests an object from the origin - ie. in the event of a cache miss. If the object is in Cache, CloudFront returns it to the viewer immediately and does not invoke Lambda@Edge functions on either of the Origin triggers.
Objects in an S3 bucket usually lend themselves well to caching, so you should find that your function only executes for the minority of requests that are cache misses. By checking the status code early in your function, you can minimise the execution time where the request results in anything other than a 404.
Note that CloudFront will cache errors as well - but make sure you have configured the TTL to suit your preference, following the documentation here.
Relevant content
- Accepted Answerasked 3 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 2 years ago