Lesson 3 of 4 Amazon CloudFront and AWS Global Accelerator

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.

Match the pairs

Reading X-Cache

Exam skills 5.3.3 · 5.3.2

Match each X-Cache value with what it means.

Log in to try this activity Interactive activities are free with an account.

Common caching problems

The following table lists the caching problems that appear in scenarios with their usual cause and fix.

SymptomCauseFix
Users see old content after a deploymentObjects cached until TTL expiryInvalidate changed paths or use versioned names; lower TTL for HTML
Low cache hit ratio, high origin loadCache key includes all headers, cookies or query strings, or origin sends no-cacheUse a cache policy with only needed values; set Cache-Control on the origin; Origin Shield
Users receive another user's personalised pagePersonalised response cached without the varying value in the keyAdd the cookie or header to the key, or mark responses private / disable caching for that path
Wrong language or device version servedAccept-Language or device header not in cache keyInclude the header (or CloudFront device headers) in the cache policy
Content never cachedOrigin returns Cache-Control: no-store/private or Set-Cookie with caching disabledFix origin headers or set a minimum TTL
502 or 504 from CloudFrontOrigin TLS problem, origin timeout or unreachable originCheck 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.

A common cause of a low cache hit ratio. A behaviour that includes all cookies and query strings in the cache key, when links carry unique tracking parameters, makes nearly every request a miss. A cache policy that includes only the values that change the response, such as the w and h query strings, with an origin request policy for anything else the origin needs, lets requests share cache entries.
Cache policies replace the legacy cache settings on a behaviour.
Troubleshooting scenario

Caching problems

Exam skills 5.3.3

Fix common CloudFront caching problems.

Log in to try this activity Interactive activities are free with an account.

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;
Worked example

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%.

Check yourself

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.