I have a Lambda@Edge origin request that is in charge of access checking. The Lambda@Edge pass the response as-is when access is granted or return a specific 401 error page (not handled with custom CloudFront error pages).
If the Lambda@Edge throws (or times out), it will make CloudFront hit the 503 custom error page and that’s cool. I want the 503 response for which the custom error page is being fetched to be cached for 5 minutes (in order to protect Lambda@Edge underlying infra in case of major problem).
I’ve configured a custom error page on 503:
# Service Unavailable
- ErrorCode: 503
ResponseCode: 503
ResponsePagePath: /errors/503.html
ErrorCachingMinTTL: 300 # 5 minutes
Those are the cache-control
HTTP response headers (rewrited by a Lambda@Edge origin response):
- 200 ->
public, max-age=31536000
- 401 ->
public, max-age=10
(I tried both with and without, stale-if-error=0
) - 503 ->
public, max-age=300
I’ve updated my Lambda@Edge origin request that is in charge of access checking to throw voluntary errors on 50% of the time.
When the Lambda@Edge origin request throws, I get a 503 error as expected but when I refresh the page in the browser (with browser cache disabled) I see on CloudWatch that CloudFront doesn’t hit the 503 error cache for 5 minutes but constantly tries to fetch the origin!
Why? Isn’t 503 errors supposed to be cached for 5 minutes and during this time for this specific URL the origin should NOT be fetched by CloudFront.
Is it special because the error comes from Lambda@Edge origin request? (I have a dead simple S3 as origin). I’ve noticed that on error I have this HTTP response header:
X-Cache: LambdaExecutionError from cloudfront
This is driving me crazy 🙂 any clue on how to cache 503 errors for 5 minutes in order to protect my Lambda@Edge origin request from being overwhelmed?
Related to CloudFront – Unexpected caching behaviour on error ?