Tutorials Logic, IN info@tutorialslogic.com

AWS Route 53 and CloudFront: DNS and CDN Design

Publish DNS Records

Route 53 provides authoritative DNS, domain registration, routing policies, and health checks. CloudFront delivers content through edge locations and shields HTTP origins from direct global traffic.

DNS decides which endpoint a name resolves to; CloudFront decides how viewer requests are cached, secured, and forwarded to an origin.

A typical web path is viewer to Route 53 alias, CloudFront distribution, and then a private S3 origin, load balancer, API endpoint, or custom server.

Use alias records for supported AWS endpoints and choose simple, weighted, latency, failover, or geolocation routing according to the traffic decision you actually need.

  • Lower TTL before a planned migration, not after it starts.
  • Keep public and private hosted zones clearly separated.
  • Validate delegation at the registrar when a hosted zone appears correct but does not resolve.

Design CloudFront Behaviors

A cache behavior selects an origin, allowed methods, viewer protocol policy, and cache/origin request policies. Include only headers, cookies, and query strings that truly change the response.

  • Use long cache lifetimes with versioned static asset names.
  • Do not cache personalized responses without a correct cache key.
  • Compress eligible content and enable HTTP/2 or HTTP/3 for viewers.

TLS and Origin Protection

Attach an ACM certificate in us-east-1 for a CloudFront custom domain. Require HTTPS from viewers and protect S3 with origin access control or restrict a custom origin so users cannot bypass CloudFront controls.

  • Redirect HTTP to HTTPS unless a stricter policy is required.
  • Add AWS WAF when edge request filtering is needed.
  • Use signed URLs or cookies for restricted content.

Deploy and Diagnose Changes

DNS changes depend on resolver caches, while CloudFront configuration deployments take time to reach the edge. Use dig, response headers, access logs, and origin logs to identify which layer served an unexpected response.

  • Prefer versioned filenames over frequent invalidations.
  • Check cache status and age headers during testing.
  • Monitor CloudFront error rates separately from origin health.

Hosted Zones and Delegation

A public hosted zone contains authoritative records for internet DNS, while a private hosted zone answers inside associated VPCs through Route 53 Resolver. Creating a hosted zone does not automatically delegate a domain registered elsewhere. The parent zone or registrar must publish the correct name-server records, and duplicate hosted zones can leave operators editing one that receives no traffic.

Use separate public and private records deliberately when split-horizon DNS is required. A private zone association controls which VPCs can resolve it, while resolver rules and endpoints extend resolution to connected networks. Verify the answer from the same network context as the failing client because a laptop, VPC workload, and public resolver may see different data.

Protect domain registration, registrar locks, contact email, DNSSEC decisions, and hosted-zone changes as critical control-plane assets. Losing a compute instance affects one service; losing authoritative DNS can redirect or remove many services at once.

  • Verify parent delegation with an external DNS trace.
  • Remove unused duplicate hosted zones.
  • Test public and private answers from their real clients.
  • Restrict domain and hosted-zone administration.

Records, Aliases, and TTL

A record name and type must match the client need: A and AAAA return addresses, CNAME points one name to another under DNS rules, and service records or text records carry other protocols and verification data. Route 53 alias records can target supported AWS resources and can be used at the zone apex where a CNAME is not allowed.

TTL controls how long recursive resolvers may cache an answer. Lower it well before a planned migration, wait for old caches to age out, then change the record. A low TTL increases query volume and does not guarantee instant client change because operating systems, applications, and intermediaries may cache separately.

For every record change, capture the old value, new value, owner, rollout time, rollback rule, and resolver evidence. Avoid depending on manually edited records for ephemeral application endpoints; have infrastructure automation create aliases to stable load balancer or CloudFront names.

  • Use alias records for supported AWS targets.
  • Reduce TTL before, not during, a migration.
  • Test A and AAAA behavior for dual-stack names.
  • Keep DNS changes reviewed and reversible.

Routing Policy Decisions

Simple routing returns the configured value without traffic steering. Weighted routing distributes DNS answers by configured weights and is useful for controlled migration, but it is not a request-perfect percentage. Latency routing selects from measured AWS Region latency, while geolocation and geoproximity make different location-based decisions. Multivalue answers can expose several healthy records.

Failover routing combines primary and secondary records with health evaluation. A health check must test the real dependency needed for service, but it should not create a circular dependency on the same DNS name. Alias targets can use target health for supported resources. Decide what happens when every endpoint is unhealthy instead of assuming DNS can repair an unavailable application.

DNS steering acts at resolver-cache granularity and cannot drain individual connections. For precise per-request shifting, use load balancer, CloudFront, application, or service-mesh controls. Test policy behavior from multiple resolvers and keep rollback records ready before moving user traffic.

  • Choose the policy from the actual steering decision.
  • Do not interpret weighted DNS as exact request distribution.
  • Keep health checks independent of the record under test.
  • Define behavior when all candidate endpoints fail.

Cache Key and Origin Request

CloudFront maps a viewer request to a cache behavior and origin, then builds a cache key from configured path, query, header, and cookie values. Only include values that truly change the response. Including every viewer field fragments the cache; omitting a response-varying identity or language field can serve the wrong content.

Cache policy controls the cache key and cache-facing TTL behavior. Origin request policy controls additional values forwarded to the origin without necessarily adding them to the key. Response headers policy can add security and CORS headers at the edge. Use managed policies only after checking that their included fields match the application contract.

Understand minimum, default, and maximum TTL together with origin cache headers. Personalized and authenticated responses need an explicit no-cache or correctly varied design. Test two users, two query variants, and an uncached error path to prove there is no cross-user content leakage.

  • Add only response-varying values to the cache key.
  • Forward origin context separately when possible.
  • Do not cache private responses by accident.
  • Test variants for both correctness and hit ratio.

Origin and Viewer Security

Require HTTPS for viewers and use a certificate whose alternate names cover every custom domain. CloudFront certificates are managed through ACM in the required Region for the service. Choose a supported security policy and redirect or reject HTTP according to the application requirement.

For an S3 origin, use origin access control with a bucket policy that permits the intended distribution, leaving the bucket private. For a custom origin, restrict direct access through security controls or a secret origin-verification mechanism appropriate to the service so users cannot bypass WAF, signed access, or edge policy.

AWS WAF filters malicious or unwanted requests, while signed URLs and signed cookies control access to private content. They solve different problems. Keep signing keys protected, use bounded expiration, and validate that cached authorization behavior cannot expose one viewers content to another.

  • Cover every alternate domain with the viewer certificate.
  • Keep S3 origins private through origin access control.
  • Prevent unreviewed direct access to custom origins.
  • Separate request filtering from content authorization.

Cache Deployment and Diagnosis

Use content-addressed or versioned filenames for static releases so a new deployment creates a new cache key. Invalidation is useful for exceptional correction but costs time and request capacity and does not fix a poor versioning strategy. HTML entry points can have shorter cache behavior while immutable assets remain long-lived.

When a response is wrong, record the viewer request, DNS answer, distribution domain, behavior path, cache status and age headers, edge request ID, origin response, and deployment time. Distinguish DNS cache, CloudFront cache, browser cache, origin logic, and an error response generated at the edge. Each layer has different evidence and recovery.

Monitor viewer error rate, origin error rate, cache hit ratio, bytes, latency, WAF actions, and origin health. Logs may contain sensitive URLs and cookies, so select fields, storage, access, and retention carefully. Test an origin failure and confirm whether cached content, origin failover, or an error response matches the intended design.

  • Prefer versioned assets over routine invalidations.
  • Capture edge request IDs during incidents.
  • Separate viewer errors from origin errors.
  • Test the configured origin-failure behavior.

DNS and Edge Examples

Route 53 alias and CloudFront invalidation example

DNS and CDN lessons become practical when learners can see both sides: traffic routing through Route 53 and cache refresh through CloudFront.

Route 53 alias and CloudFront invalidation example
aws cloudfront create-invalidation \
  --distribution-id E123456789ABC \
  --paths "/*"
aws route53 change-resource-record-sets \
  --hosted-zone-id Z123456ABCDEFG \
  --change-batch file://alias-record.json
  • Invalidations are useful after static asset or SPA route deployments.
  • Alias records are the normal Route 53 pattern for AWS-managed endpoints.

Change an Origin Without a Long Outage

A static site moves to a new private origin while its public hostname must remain stable.

Change an Origin Without a Long Outage
Constraints: DNS TTL is 300 seconds, CloudFront uses an origin access control, and cached objects may outlive the deployment.
Decision: Add and test the new origin, switch the behavior, invalidate only changed paths, then change DNS only if the distribution hostname changes.
Verification: Two regions resolve the expected alias, CloudFront returns the new version, and direct origin access remains denied.
Failure test: Restore the prior behavior and prove rollback does not require waiting for an unrelated DNS cache.
Output
Expected evidence: Two regions resolve the expected alias, CloudFront returns the new version, and direct origin access remains denied.
  • This is a worked engineering decision, so the result is operational evidence rather than terminal output.
Before you move on

AWS Route 53 and CloudFront: DNS and CDN Design Mastery Check

5 checks
  • DNS routing policy matches the intended traffic decision.
  • The cache key contains only response-varying values.
  • TLS covers every alternate domain name.
  • The origin cannot be bypassed unintentionally.
  • Deployment verification checks DNS, edge, and origin layers.
Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.