Troubleshooting CloudFront Caching and Interpreting Logs
This lesson explains how metrics, headers and logs show how CloudFront handled each request, so you can identify and remediate caching issues and interpret CloudFront logs as the exam guide asks.
Learning outcomes
After completing this lesson, you will be able to:
- Diagnose caching with the X-Cache header and metrics.
- Fix common caching problems.
- Interpret standard and real-time logs.
Diagnosing caching behaviour
The X-Cache response header shows Hit from cloudfront, RefreshHit from cloudfront (revalidated with the origin), Miss from cloudfront or Error from cloudfront, and the Age header shows how long an object has been cached. CloudWatch metrics include Requests, BytesDownloaded, 4xxErrorRate and 5xxErrorRate by default, and with additional metrics enabled, CacheHitRate, OriginLatency and error rates by status code. The console's cache statistics, popular objects and top referrers reports show hit and miss counts by object.
Reading X-Cache
Common caching problems
The following table lists the caching problems that appear in scenarios with their usual cause and fix.
| Symptom | Cause | Fix |
|---|---|---|
| Users see old content after a deployment | Objects cached until TTL expiry | Invalidate changed paths or use versioned names; lower TTL for HTML |
| Low cache hit ratio, high origin load | Cache key includes all headers, cookies or query strings, or origin sends no-cache | Use a cache policy with only needed values; set Cache-Control on the origin; Origin Shield |
| Users receive another user's personalised page | Personalised response cached without the varying value in the key | Add the cookie or header to the key, or mark responses private / disable caching for that path |
| Wrong language or device version served | Accept-Language or device header not in cache key | Include the header (or CloudFront device headers) in the cache policy |
| Content never cached | Origin returns Cache-Control: no-store/private or Set-Cookie with caching disabled | Fix origin headers or set a minimum TTL |
| 502 or 504 from CloudFront | Origin TLS problem, origin timeout or unreachable origin | Check origin certificate, protocol policy, security groups and origin timeouts |
The following diagram compares a cache key that includes everything with one that includes only what changes the response.

Caching problems
CloudFront logs
Standard logs (access logs) record every request. Standard logging v2 delivers them to CloudWatch Logs, Amazon Data Firehose or S3, in formats including JSON and Parquet with selectable fields; legacy standard logging delivers to S3 buckets with ACLs enabled. Key fields are x-edge-location, sc-status, cs-uri-stem, x-edge-result-type (Hit, RefreshHit, Miss, LimitExceeded, CapacityExceeded, Error, Redirect), x-edge-detailed-result-type (for example OriginShieldHit or a specific error), time-taken and time-to-first-byte. Real-time logs are delivered within seconds to Kinesis Data Streams with configurable sampling. Athena or Logs Insights queries over the logs show hit ratios per path and error sources.
SELECT cs_uri_stem, x_edge_result_type, count(*) AS requests
FROM cloudfront_logs
WHERE "date" = DATE '2026-10-14'
GROUP BY cs_uri_stem, x_edge_result_type
ORDER BY requests DESC
LIMIT 25;A 12% cache hit ratio
A media site's distribution has a cache hit ratio of 12% and the origin is overloaded. Logs show that most requests for the same image are misses. The default behaviour uses a legacy configuration that forwards all cookies and all query strings, and the marketing team appends unique tracking parameters (utm_*) to every link. The operator switches the behaviour to a cache policy that includes no cookies and only the w and h resize query strings, with an origin request policy that forwards nothing else. Enabling Origin Shield in the origin's Region further consolidates misses. The hit ratio rises above 90%.
Users see an old file after a release. Name two fixes.
Show answer
Invalidate the path, or version file names so new content has a new URL.
Exam Tips
Remember for the exam
- X-Cache and x-edge-result-type show Hit, RefreshHit, Miss or Error.
- Stale content: invalidate or version file names.
- Low hit ratio: trim the cache key and fix origin Cache-Control headers.
- Standard logs v2 go to CloudWatch Logs, Firehose or S3; real-time logs go to Kinesis Data Streams.
- Enable additional metrics for CacheHitRate.