Tal
Tal

Reputation: 7997

CloudFront report showing 404 URLs

There are URLs in my cloudfront that are returning 404. Once I invalidate them, all is well. I assume that at some point in time the origin server returned 404, which was cached by cloudfront.

Is there a way to generate a CloudFront report showing the URLs that are marked as missing? (404s)
Is there a way to create an alert for new ones?

Upvotes: 1

Views: 2884

Answers (2)

Tal
Tal

Reputation: 7997

on top of @alexjs answer above, one could also set the 404 cache period to 0. In my case, that was the desired behavior as 404s should never happen are usually suggest server issue.

Upvotes: 1

alexjs
alexjs

Reputation: 573

As you've observed, CloudFront by default caches errors.

Are the 404s valid URLs? A common issue is something as part of an application which requests a URL (e.g. a file) to determine its presence before uploading / publishing. This obviously backfires a bit if you have a caching layer.

Is there a way to generate a CloudFront report showing the URLs that are marked as missing? (404s)

These will be written to CloudFront logs.

Is there a way to create an alert for new ones? You could use CloudWatch Alarms to alert based on 4xx/5xx error rate, but this wouldn't give you granularity into the URIs themselves.

You could use a Lambda function which is invoked upon log delivery to your given S3 bucket, configured to parse them for 4xx, and then sends a notification to you (SNS/SES/etc)

Upvotes: 0

Related Questions