AWS from zero · Part 2: Networking and compute · Lesson 14 of 38 · about 55 minutes

Route 53, CloudFront, certificates and WAF

The bakery's shop at the edge of AWS. A Route 53 zone answers for the shop's name, but the rest of the internet never asks it, and that turns out to be the most important thing about DNS. A private bucket goes behind CloudFront with HTTPS, a cache hit and a 403 for anyone who skips it. A certificate is requested and stays pending, for a good reason. And a web application firewall blocks an admin path, a script injection and a flood of requests. All for under 5 cents.

By the end you'll know

  • How a name becomes an address, and the difference between registering a domain and hosting its DNS
  • The record types you'll meet, and why AWS has alias records
  • What CloudFront does, how to read its cache headers, and how to keep people from going around it
  • How certificates are issued and validated, and why CloudFront's must be in us-east-1
  • What WAF rules, managed rule groups and rate limits do, and what Shield adds
  • Route 53's routing policies, for the exam

Before you start

  • You need: the juniper-rye profile from Lesson 4, signed in. No server, no VPC: everything here runs at AWS's edge.
  • The script: edge-lab.sh from the practice folder's lesson-14. Everything it creates is named jr-lesson14-*, and its delete step removes it.
  • How the script talks to AWS: only through the AWS CLI. The few lines of Python in it just turn the CLI's JSON into readable tables and never connect to AWS; boto3, AWS's Python library, comes in Lesson 20.
  • To see every call the script makes, put SHOW=1 in front of any step, such as SHOW=1 ./edge-lab.sh cdn. The lesson's "By hand" section lists them all too.
  • dig, a tool that asks DNS questions. Macs and most Linux machines have it; the script falls back to Route 53's own test tool without it.
  • Where you run things: your own machine, labeled (Your machine).
  • Every output below is from a real run on November 10, 2026.

Two things here bill by the month, not the hour

A hosted zone is $0.50 a month, but nothing if you delete it within 12 hours of creating it. A web ACL is $5 a month plus $1 per rule, charged by the hour, so this lab's is about a cent. Forgotten, the pair is about $9 a month. Run delete the same evening; it tells you how long the zone existed.

The short version

  • Registering a domain and hosting its DNS are different things. A hosted zone answers questions, but the world only asks it once the domain's registration points there.
  • CloudFront is a content delivery network: copies of your site at hundreds of edge locations, with HTTPS included.
  • An origin access control lets only CloudFront read the bucket, so nobody can go around it.
  • Certificate Manager issues free certificates once you prove you control the name, by publishing a DNS record. For CloudFront they must be in us-east-1.
  • WAF filters requests before they reach the site: your own rules, AWS's managed rule groups, and rate limits.

What this lesson costs

PartCost
Route 53 hosted zone$0.50 a month; nothing if deleted within 12 hours
DNS queries$0.40 per million; queries for alias records pointing at AWS are free
CloudFrontAlways free up to 1 TB and 10 million requests a month
Public certificates from Certificate Manager$0
WAF web ACL$5 a month, plus $1 per rule and $0.60 per million requests, by the hour
S3, one small fileA fraction of a cent
This lessonUnder 5 cents, from credits
If it were left runningAbout $9 a month

How a name becomes an address

Lesson 12's load balancer had a long AWS name, and Lesson 7's server only an IP address. Real shops have a name like shop.juniperandrye-lab.com. Turning that name into an address is the job of DNS (the Domain Name System), and the Networking track's DNS lesson covers it without AWS. The short version: your computer asks a resolver (your internet provider's, or a public one like 1.1.1.1), and the resolver asks a chain of servers, from the root, to the servers for .com, to the name servers for the domain itself, which hold the answer.

Two separate jobs make that chain work for a domain:

RegisteringHosting the DNS
What it isRenting the name from the registry, through a registrarRunning the name servers that hold its records
What it decidesWhich name servers the world asksWhat they answer
In AWSRoute 53 Domains: about $15 a year for a .comA Route 53 hosted zone: $0.50 a month
ElsewhereNamecheap, Cloudflare, Squarespace and many moreCloudflare, your registrar, your own servers

You can register a name in one place and host its DNS in another. The link between them is a set of NS (name server) records at the registry: "for this name, ask these servers". This lesson doesn't register anything, which is the point of the diagram:

The lab's zone answers when asked directly. Nobody else will ever ask it, because the name isn't registered.

Is it allowed, and what does it cost?

(Your machine)

BASH
cd ~/Apps/aws-practice/lesson-14
chmod +x edge-lab.sh
./edge-lab.sh fence
OUTPUT
== Is this allowed? (these services have no dry run, so this reads instead)
  Route 53 (global)                      allowed
  CloudFront (global)                    allowed
  S3 in us-east-2                        allowed
  Certificate Manager in us-east-1       allowed
  WAF for CloudFront, in us-east-1       allowed
== Is juniperandrye-lab.com free? The lab needs a name nobody owns
  not registered: NXDOMAIN from the world's name servers
== What it costs
  hosted zone:        $0.50 a month, but nothing if deleted within 12 hours of creation
  DNS queries:        $0.40 per million; alias queries to CloudFront are free
  CloudFront:         always free up to 1 TB and 10 million requests a month
  certificate (ACM):  public certificates are free
  WAF:                $5 a month per web ACL and $1 per rule, by the hour: about 1 cent for this lab
  S3:                 one small file: a fraction of a cent
  this lab: under 5 cents, if delete runs within 12 hours

Route 53 and CloudFront are global services: they don't live in a Region. Two things that serve CloudFront do: its certificates and its firewall rules must be created in us-east-1, whichever Region the rest of your work is in. The new sign-up's free plan keeps you to one Region, so the fence checks us-east-1 specifically. It allowed both.

The fence also checks that nobody owns the lab's domain. NXDOMAIN, "no such domain", from the world's name servers means it isn't registered. Why that check exists comes next.

A hosted zone

In the console: Route 53 > Hosted zones > Create hosted zone, type Public hosted zone. Then Create record inside it.

(Your machine)

BASH
./edge-lab.sh dns
OUTPUT
== A public hosted zone for juniperandrye-lab.com
== The zone's own name servers: Route 53 gave it four, in four different top-level domains
  ns-1517.awsdns-61.org
  ns-1631.awsdns-11.co.uk
  ns-303.awsdns-37.com
  ns-874.awsdns-45.net
== Adding records
  juniperandrye-lab.com.     MX     3600  10 mail.juniperandrye-lab.com
  juniperandrye-lab.com.     NS     172800 (made by Route 53)
  juniperandrye-lab.com.     SOA    900   (made by Route 53)
  juniperandrye-lab.com.     TXT    3600  "juniper-and-rye: fresh bread daily"
  shop.juniperandrye-lab.com. A      300   192.0.2.10
  www.juniperandrye-lab.com. CNAME  300   shop.juniperandrye-lab.com
== Asking the zone's own name server
    shop.juniperandrye-lab.com, A:
      192.0.2.10
    www.juniperandrye-lab.com, CNAME:
      shop.juniperandrye-lab.com.
    juniperandrye-lab.com, MX:
      10 mail.juniperandrye-lab.com.
== Asking the world (a public resolver, 1.1.1.1), the way a browser does
    shop.juniperandrye-lab.com, A:
      status NXDOMAIN
    who answers for juniperandrye-lab.com (NS):
      status NXDOMAIN

Route 53 gave the zone four name servers, in .org, .co.uk, .com and .net, so a problem with any one top-level domain can't take the zone down. It also made two records itself: NS, listing those four, and SOA (start of authority), the zone's housekeeping record. The lab added four more, one of each common kind, and asked a zone name server directly with dig @ns-303.awsdns-37.com. Each answered. Then it asked 1.1.1.1, the way any browser would, and got NXDOMAIN for both.

TypeHoldsIn the lab
AAn IPv4 addressshop to 192.0.2.10, an address set aside for documentation that goes nowhere
AAAAAn IPv6 addressNone
CNAMEAnother name: "ask about that name instead"www to shop
AliasRoute 53's own kind: an A or AAAA record that follows an AWS resource's addressesNext section
MXThe mail servers for the domain, with a priority10 mail.juniperandrye-lab.com
TXTAny text: ownership proofs, email security settingsA note
NS and SOAThe zone's name servers and housekeepingMade by Route 53

The number after each name is the TTL (time to live) in seconds: how long resolvers may keep the answer before asking again. 300 is five minutes. Before changing an important record, teams lower its TTL a day ahead, so the change spreads in minutes rather than hours.

A zone isn't ownership

The first run of this lab used juniperandrye.com. Route 53 created the zone without complaint and answered for it when asked directly. But the world's answers came back from a completely different set of name servers: that name is registered, to someone who isn't us, and the registry sends everyone to their name servers.

That's how it should be. Anyone can create a hosted zone for any name, including yours, and it does nothing, because the world only asks the name servers the registration points to. Control of a domain is control of its registration. That's also why the script now checks the domain first, and the lab uses juniperandrye-lab.com, a name nobody has registered.

CloudFront in front of a private bucket

CloudFront is AWS's CDN (content delivery network): it keeps copies of your site at edge locations, over 750 of them in cities around the world, and answers each visitor from one near them. Behind it is the origin, where the real files live: here, an S3 bucket. Lesson 15 covers S3 properly; for now it's a private folder holding one page.

PartWhat it does
DistributionOne CloudFront setup, with its own address like d3hmsajq4dhix7.cloudfront.net
OriginWhere CloudFront fetches what it doesn't have: a bucket, a load balancer, any web server
Cache behaviorRules for a set of paths: which origin, HTTP or HTTPS, how long to keep copies
Origin access control (OAC)CloudFront signs its requests to the bucket, and the bucket's policy allows only that one distribution
Price classWhich parts of the world's edge locations to use. The lab's, PriceClass_100, is North America and Europe.

In the console: CloudFront > Distributions > Create distribution, pick the bucket as the origin, choose Origin access control settings, and let it update the bucket policy. Set Viewer protocol policy to Redirect HTTP to HTTPS.

(Your machine)

BASH
./edge-lab.sh cdn
OUTPUT
== A private bucket, jr-lesson14-shop-42014c, in us-east-2 (Lesson 15 covers S3 properly)
== A CloudFront distribution in front of the bucket
  E1JDQEX9AGOYYY: deploying to the edge locations (usually 3 to 6 minutes)
  deployed after 181 seconds
== Its address: d3hmsajq4dhix7.cloudfront.net
== 1. Plain HTTP
      HTTP/1.1 301 Moved Permanently
      Server: CloudFront
      Location: https://d3hmsajq4dhix7.cloudfront.net/
      X-Cache: Redirect from cloudfront
      X-Amz-Cf-Pop: IAD61-P2
== 2. HTTPS, first request
      HTTP/2 200 
      server: AmazonS3
      x-cache: Miss from cloudfront
      x-amz-cf-pop: IAD61-P2
== 3. HTTPS, the same page again
      HTTP/2 200 
      server: AmazonS3
      x-cache: Hit from cloudfront
      x-amz-cf-pop: IAD61-P2
== 4. Straight to the bucket, skipping CloudFront
      HTTP/1.1 403 Forbidden
      Server: AmazonS3
== The page
    <!doctype html><title>Juniper &amp; Rye</title>
    <h1>Juniper &amp; Rye</h1><p>Fresh from the oven, served from a CloudFront edge near you.</p>
== Before any firewall
  /admin                             403, from S3: the bucket said no
  /?q=<script>alert(1)</script>      200

Four requests, read top to bottom:

RequestAnswerWhat it shows
Plain HTTP301, to the HTTPS addressThe redirect setting. CloudFront answered itself, without asking the bucket.
HTTPS, first200, Miss from cloudfrontThe edge had no copy, so it fetched one from the bucket
HTTPS, again200, Hit from cloudfrontServed from the edge's copy, without touching the bucket
The bucket directly403The bucket only answers CloudFront, so nobody can go around it

x-amz-cf-pop: IAD61-P2 names the edge location, the "point of presence", that answered. Edge locations are named after the nearest airport: IAD is Washington Dulles, the closest to the lab. HTTPS worked straight away, on CloudFront's own address, with CloudFront's own certificate. Your own name needs your own certificate, which is next.

Two more requests ran before any firewall existed, to compare with later. /admin got a 403 from S3, because there's no such file and the bucket won't say what it holds. The <script> one, an attempt to make a page run someone else's code, got a 200: nothing stopped it.

When a page changes, the edges keep their old copies until they expire. An invalidation tells them to drop them now: the first 1,000 paths a month are free.

Giving it a name

In the console: Route 53 > Hosted zones > the zone > Create record, turn on Alias, and choose Alias to CloudFront distribution. Then Certificate Manager, in US East (N. Virginia) > Request > Request a public certificate, with DNS validation, and Create records in Route 53.

(Your machine)

BASH
./edge-lab.sh name
OUTPUT
== Pointing shop.juniperandrye-lab.com at CloudFront, with an alias record
    shop.juniperandrye-lab.com, A, from the zone's own name server:
      3.162.115.225
      3.162.115.208
      3.162.115.181
      3.162.115.84
== Pretend the world asked our zone: connect to 3.162.115.225 as shop.juniperandrye-lab.com
    curl: (60) SSL: no alternative certificate subject name matches target hostname 'shop.juniperandrye-lab.com'
    subject: CN=*.cloudfront.net
    subjectAltName does not match hostname shop.juniperandrye-lab.com
    SSL: no alternative certificate subject name matches target hostname 'shop.juniperandrye-lab.com'
== Asking for a certificate for shop.juniperandrye-lab.com, in us-east-1
  status: PENDING_VALIDATION
  to prove you own shop.juniperandrye-lab.com, publish this record:
    _bcd9c6f5878fad9bc30edd998b55bab6.shop.juniperandrye-lab.com. CNAME
    -> _48cc852abd00d7557c3644376938504d.wzccmgtwzk.acm-validations.aws.
== Published it in our zone. Waiting 2 minutes for Certificate Manager to look
  status: PENDING_VALIDATION
== Why: who does the world ask about juniperandrye-lab.com?
    our zone's name servers:
      ns-1517.awsdns-61.org
      ns-1631.awsdns-11.co.uk
      ns-303.awsdns-37.com
      ns-874.awsdns-45.net
    the world's answer:
      status NXDOMAIN
    the validation record, asked of the world:
      status NXDOMAIN

Alias records

The lab replaced shop's A record with an alias to the distribution, and the zone now answers with four CloudFront addresses. An alias looks like an A record to the world, but Route 53 fills in the addresses itself and keeps up as CloudFront changes them. Compared with a CNAME:

CNAMEAlias
Points atAny name, anywhereAWS resources: CloudFront, load balancers, S3 websites, other records in the zone
At the bare domain, juniperandrye-lab.comNot allowed by the DNS rulesAllowed
QueriesChargedFree, when it points at an AWS resource

The middle row is the exam favorite: a bare domain, the "apex", can't be a CNAME, so pointing it at a load balancer or CloudFront needs an alias.

The wrong certificate

The lab then connected to a CloudFront address while calling itself shop.juniperandrye-lab.com, exactly as a browser would once the world could find the name. curl refused: the certificate CloudFront offered was for *.cloudfront.net, and a certificate is only good for the names written in it. A browser shows that as a full-page warning. CloudFront needs a certificate that names the shop, and it needs telling that the shop is one of its names.

A certificate that can't be issued

Certificate Manager (ACM) issues certificates for free and renews them on its own, but first you prove you control the name. With DNS validation, it gives you a CNAME record to publish, then looks it up the way the world would. The lab published the record, in our zone, and waited two minutes. Still PENDING_VALIDATION, and the end of the output shows why: Certificate Manager asked the world, the world found no such domain, and our zone was never asked.

That's the whole system working. If creating a zone were enough to get a certificate, anyone could get one for your bank's name. Proving control means proving the registration points at you. With a registered domain whose NS records point at the zone, the same record turns the certificate to ISSUED within minutes, and the rest is three settings on the distribution: the name under Alternate domain names, the certificate under Custom SSL certificate, and the alias record you already have.

For CloudFront, the certificate must be in us-east-1. A certificate for a load balancer must be in the load balancer's own Region. The exam asks about both.

A web application firewall

AWS WAF (web application firewall) looks at each request before CloudFront serves it, and allows, blocks or counts it. Lesson 9's security groups and network ACLs judge addresses and ports; WAF reads the request itself: its path, its query string, its headers, how often its sender has been asking.

PartWhat it doesThe lab's
Web ACLThe set of rules, in priority order, attached to CloudFront, a load balancer or API Gatewayjr-lesson14-waf, allowing anything no rule blocks
Your own ruleMatches part of a requestblock-admin: block any path starting with /admin
Managed rule groupRules written and kept up to date by AWS, or sellers in AWS Marketplaceaws-common-rules: AWS's core rule set, for common attacks
Rate-based ruleBlocks any one address sending more than a limit in a time windowrate-limit: more than 10 a minute

In the console: WAF & Shield > Web ACLs > Create web ACL, resource type Amazon CloudFront distributions, then Add rules. Or from the distribution: Security tab > Edit.

(Your machine)

BASH
./edge-lab.sh waf
OUTPUT
== A web ACL for CloudFront, in us-east-1, with three rules
== Attaching it to the distribution
  deployed after 121 seconds
== Trying to get past it
  the home page                      200
  /admin                             403, from WAF: blocked
  /?q=<script>alert(1)</script>      403, from WAF: blocked
== One request a second, more than the 10 a minute the rate rule allows
  after  16 seconds:  15 allowed,   0 blocked
  after  32 seconds:  20 allowed,  10 blocked
  after  32 seconds:  20 allowed,  10 blocked (first block at 22 seconds)
== What WAF saw, from its sample of the last 15 minutes
  block-admin        1 BLOCK
  aws-common-rules   1 BLOCK
  rate-limit         1 BLOCK
  jr-lesson14-waf    18 ALLOW

The same three requests as before the firewall. /admin is still a 403, but now WAF sent it, and the bucket never saw the request. The <script> request, a 200 before, was caught by AWS's managed rules, without anyone writing a rule for it. Telling the two kinds of 403 apart is why the script reads the page that comes back: S3's says AccessDenied, WAF's says Request blocked.

The rate limit isn't exact. It allows 10 requests a minute, yet 20 got through before the first block at 22 seconds. WAF counts requests and checks the totals every few seconds, so a burst gets a little past before the block lands. Rate rules stop floods, not the eleventh request.

The last section is WAF's sample of requests, not a count: it keeps a selection to show what each rule matched. Every rule shows up there, which is how you check a new rule matches what you meant. For full counts, WAF sends metrics to CloudWatch (Lesson 32), and full logs to a bucket or CloudWatch Logs.

And Shield

AWS Shield Standard protects every CloudFront distribution and Route 53 zone against the common network floods, DDoS (distributed denial of service) attacks, automatically and for free; nothing to switch on. Shield Advanced is $3,000 a month, for a year at a time, with a response team and cost protection during attacks. The free plan doesn't offer it, and a bakery doesn't need it.

Routing policies

The lab's records always give the same answer. Route 53 can choose the answer per question, and the Solutions Architect exam asks which policy fits which need. Described here, not built:

PolicyAnswers withFits
SimpleThe same records, every timeOne site, one place. The lab's.
FailoverThe primary while its health check passes, the standby when it failsA backup site in another Region (Lesson 19)
WeightedRecords in proportion: 90% one, 10% the otherTrying a new version on a few visitors
LatencyThe Region with the lowest delay for that visitorThe same site in several Regions
GeolocationBy the visitor's country or continentLanguage, or laws about where data may go
GeoproximityBy distance, with a dial to pull more visitors to one placeShifting traffic between Regions gradually
Multivalue answerUp to 8 healthy records, picked at randomSimple spreading, with health checks
IP-basedBy the visitor's network address rangeSending one company's offices somewhere specific

Health checks ($0.50 a month each, for AWS endpoints) are what make failover, multivalue and the others skip a broken answer. The lab doesn't make one, because it has nothing in a second Region to fail over to.

Take it down

In the console: CloudFront > the distribution > Disable, wait for it to finish deploying, then Delete. Then WAF & Shield > Web ACLs > Delete; Certificate Manager (us-east-1) > Delete; S3 > the bucket > Empty, then Delete; and Route 53 > the zone: delete every record but NS and SOA, then Delete zone.

(Your machine)

BASH
./edge-lab.sh delete
OUTPUT
== Disabling the distribution and detaching the firewall (CloudFront takes a few minutes)
== Deleted distribution E1JDQEX9AGOYYY
== Deleted the origin access control
== Deleted web ACL jr-lesson14-waf
== Deleted the certificate request
== Deleted bucket jr-lesson14-shop-42014c
== Deleted the hosted zone for juniperandrye-lab.com
  it existed for 13 minutes: under 12 hours, so it isn't charged
== Left over from this lab
  hosted zones:        0
  distributions:       0
  web ACLs:            0
  certificates:        0
  buckets:             0
== Things that bill monthly, anywhere in the account
  hosted zones:        0
  CloudFront web ACLs: 0

CloudFront won't delete a distribution that's switched on. It has to be disabled first, and that change spreads to every edge location before the delete is allowed, which is most of this step's ten minutes. The firewall comes off in the same change, because a web ACL attached to anything can't be deleted. A hosted zone can't be deleted while it holds records of its own, so the script deletes those first, leaving the NS and SOA records Route 53 made.

By hand: every command the script runs

The same lab without the script, in order. It leaves out tags and waiting loops; SHOW=1 ./edge-lab.sh cdn prints the exact calls as they run. The JSON files are the ones the script writes; SHOW=1 shows their names. (Your machine)

BASH
export AWS_PROFILE=juniper-rye
DOMAIN=juniperandrye-lab.com

# A hosted zone, and records added with a change batch (a JSON list of changes)
ZONE=$(aws route53 create-hosted-zone --name "$DOMAIN" --caller-reference "lab-$(date +%s)" \
  --query HostedZone.Id --output text)
aws route53 change-resource-record-sets --hosted-zone-id "$ZONE" --change-batch file://records.json
dig @ns-303.awsdns-37.com shop.$DOMAIN A        # ask the zone's own name server
dig @1.1.1.1 shop.$DOMAIN A                     # ask the world

# A private bucket, one page, and an origin access control
BUCKET=jr-lesson14-shop-42014c
aws s3api create-bucket --bucket "$BUCKET" --region us-east-2 --create-bucket-configuration LocationConstraint=us-east-2
aws s3 cp index.html "s3://$BUCKET/index.html" --content-type text/html
OAC=$(aws cloudfront create-origin-access-control --origin-access-control-config \
  Name=jr-lesson14-oac,SigningProtocol=sigv4,SigningBehavior=always,OriginAccessControlOriginType=s3 \
  --query OriginAccessControl.Id --output text)

# The distribution, then a bucket policy allowing only it
DIST=$(aws cloudfront create-distribution-with-tags --distribution-config-with-tags file://dist.json \
  --query Distribution.Id --output text)
aws s3api put-bucket-policy --bucket "$BUCKET" --policy file://policy.json
aws cloudfront wait distribution-deployed --id "$DIST"
curl -sI "https://$(aws cloudfront get-distribution --id "$DIST" --query Distribution.DomainName --output text)/"

# An alias record, and a certificate request (in us-east-1, for CloudFront)
aws route53 change-resource-record-sets --hosted-zone-id "$ZONE" --change-batch file://alias.json
CERT=$(aws acm request-certificate --region us-east-1 --domain-name "shop.$DOMAIN" --validation-method DNS \
  --query CertificateArn --output text)
aws acm describe-certificate --region us-east-1 --certificate-arn "$CERT" \
  --query 'Certificate.DomainValidationOptions[0].ResourceRecord'

# The firewall (also in us-east-1), attached by updating the distribution
aws wafv2 create-web-acl --region us-east-1 --scope CLOUDFRONT --name jr-lesson14-waf \
  --default-action Allow={} --rules file://rules.json --cli-binary-format base64 \
  --visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName=jr-lesson14-waf
aws cloudfront get-distribution-config --id "$DIST" > current.json   # set WebACLId, keep the ETag
aws cloudfront update-distribution --id "$DIST" --if-match "$ETAG" --distribution-config file://updated.json

# Taking it down, in this order
aws cloudfront update-distribution --id "$DIST" --if-match "$ETAG" --distribution-config file://disabled.json
aws cloudfront wait distribution-deployed --id "$DIST"
aws cloudfront delete-distribution --id "$DIST" --if-match "$NEW_ETAG"
aws cloudfront delete-origin-access-control --id "$OAC" --if-match "$OAC_ETAG"
aws wafv2 delete-web-acl --region us-east-1 --scope CLOUDFRONT --name jr-lesson14-waf --id "$ACL_ID" --lock-token "$LOCK"
aws acm delete-certificate --region us-east-1 --certificate-arn "$CERT"
aws s3 rb "s3://$BUCKET" --force
aws route53 change-resource-record-sets --hosted-zone-id "$ZONE" --change-batch file://delete-records.json
aws route53 delete-hosted-zone --id "$ZONE"

CloudFront changes are optimistic locking in action: every read returns an ETag, a version number, and every change must quote it. If someone changed the distribution in between, the update is refused instead of overwriting their change.

In real systems

  • Every domain the business owns is registered in one place, locked against transfer, and set to auto-renew. An expired domain is a dead site and, worse, a name someone else can buy.
  • Records pointing at deleted resources get cleaned up, or someone can claim the resource and serve their content on your name. It's called a subdomain takeover.
  • Static sites are often just this: a private bucket, CloudFront, a certificate and an alias record, for pennies a month.
  • Dynamic sites put CloudFront in front of the load balancer too, with WAF on the distribution, so attacks are stopped at the edge before they reach a server.
  • New WAF rules start in Count mode, which logs what they would block without blocking it, until the team is sure they don't catch real customers.
  • All of it is Terraform (Lesson 28), because a distribution's settings run to hundreds of lines.

Spot the problem

Work out what's wrong before you read the explanation.

"My certificate is issued, but CloudFront won't let me pick it." A team runs everything in us-east-2. They request a certificate for shop.example.com in Certificate Manager, validate it, and it shows ISSUED. In CloudFront's Custom SSL certificate list, it isn't there. What's wrong? CloudFront only uses certificates from us-east-1, whichever Region the rest of the work is in. The fix: request the certificate again in us-east-1, validate it with the same DNS record (it's usually identical), and pick that one. Then check: does curl -sI https://shop.example.com/ answer with no certificate error?

Keep this

RememberWhy
Registering and hosting are separateThe registration decides which name servers the world asks
A zone isn't ownershipAnyone can make one; nobody asks it
Alias, not CNAME, at the bare domainDNS forbids a CNAME there, and alias queries are free
Origin access control on the bucketNobody goes around CloudFront
x-cache: HitServed from the edge, without touching the origin
Certificates for CloudFront: us-east-1Load balancers use their own Region's
Certificates are free, and validated by DNSProof of control, then automatic renewal
WAF reads requests; security groups read addressesDifferent layers, use both
Delete the zone within 12 hoursOr it's $0.50 for the month

Where you are now

The bakery has a DNS zone you've questioned directly and watched the world ignore, a page served over HTTPS from an edge location near you with a bucket nobody else can read, a certificate request that showed exactly what owning a name means, and a firewall that blocked an admin path, a script injection and a flood of requests. Part 2 is done. Next, Part 3 starts with Lesson 15, S3: the storage behind this lesson's page, its permissions, and what happens to files over time.

Check yourself

  1. The lab's zone answered for shop.juniperandrye-lab.com, but 1.1.1.1 said NXDOMAIN. Why?

  2. What does the second request's 'x-cache: Hit from cloudfront' tell you?

  3. Why did the request straight to the bucket get a 403?

  4. Why does the bare domain, juniperandrye-lab.com, need an alias rather than a CNAME to point at CloudFront?

  5. The certificate stayed PENDING_VALIDATION even with its record in the zone. Why?

  6. /admin got a 403 both before and after the firewall. What changed?

  7. Which routing policy sends visitors to the standby site only when the main one fails its health check?

Key terms

  • DNS (Domain Name System): turns names into addresses.
  • Resolver: the server that asks the chain of name servers on your behalf.
  • Registrar and registry: who you rent a domain through, and who keeps the list for its ending, like .com.
  • Hosted zone: Route 53's container for one domain's records.
  • Name server (NS) record: says which servers answer for a domain.
  • TTL (time to live): how long an answer may be kept before asking again.
  • Alias record: Route 53's A record that follows an AWS resource's addresses.
  • CDN (content delivery network): copies of a site at locations around the world.
  • Edge location: where CloudFront answers visitors from.
  • Origin: where CloudFront fetches what it doesn't have.
  • Origin access control (OAC): lets only one distribution read a bucket.
  • Invalidation: telling the edges to drop their copies.
  • ACM (AWS Certificate Manager): issues and renews certificates.
  • DNS validation: proving control of a name by publishing a record.
  • WAF (web application firewall): allows or blocks requests by their content and rate.
  • Web ACL: a set of WAF rules attached to a resource.
  • Managed rule group: rules written and maintained by AWS or a seller.
  • Shield: AWS's DDoS protection; Standard is free and automatic.

Go deeper