Laptop to Production

Domain names and HTTPS

Route 53, certificates and a padlock in the browser.

Time
45 minutes
Level
Beginner

Part 1: The problem

QuickCart, the first app release

The QuickCart app needed an address for its API. Noor, the mobile developer, copied the load balancer’s name from the console — a long string ending in elb.amazonaws.com — and put it straight into the app.

It was plain http://. iOS refused to connect, so Noor added an exception to App Transport Security to allow it.

A month later, the team rebuilt the load balancer. Its name changed. Every installed copy of the app now pointed at an address that no longer existed. Fixing it meant shipping an app update, waiting for review, and waiting again for customers to install it.

QuickCart needs three things:

  • An address it owns, like example.com, that stays the same whatever changes behind it.
  • A certificate, so the app talks HTTPS with no exceptions.
  • A certificate that renews itself, so nobody has to remember.

Part 2: The idea

Computers find each other by IP address, like 203.0.113.10. People and apps use names, like example.com. DNS — the Domain Name System — is the internet’s way of turning a name into an address.

Where a name’s answer comes from

No single computer knows every name. A lookup is a chain of questions, and each server only knows who to ask next:

WhoWhat they knowTheir answer for example.com
ResolverNothing permanent. It asks on your behalf and remembers answers for a while. Run by your Wi-Fi, your mobile network, or a public service“Let me find out”
Root serversWho runs each ending, like .com or .org“Ask the .com servers”
.com serversWhich name servers are in charge of each .com domain“Ask these four name servers”
Your name serversYour actual records“It’s 203.0.113.10”

The resolver saves each answer for a number of seconds set by the record, called its TTL — time to live. That’s why a change can take a while to reach everyone.

The registrar and the hosted zone

Two different companies can be involved, and people mix them up:

PieceWhat it isQuickCart’s
RegistrarWhere you bought the domain. It tells the .com servers which name servers are in chargeAny registrar, including Route 53 itself
Hosted zoneWhere the records live. In Route 53, one hosted zone per domainThe example.com hosted zone
NS recordThe list of name servers in charge. Route 53 gives every hosted zone fourCopied from the hosted zone into the registrar

Creating a hosted zone doesn’t make anyone use it. The registrar has to point to it. If you bought the domain through Route 53, that’s done for you. Anywhere else, you copy the hosted zone’s four name servers into the registrar’s settings. This is called delegation.

Key point: The registrar decides which name servers answer for your domain. Nothing in Route 53 matters until it points there.

The records you’ll use

TypePoints a name atExample
AAn IPv4 addressexample.com → 203.0.113.10
AAAAAn IPv6 addressexample.com → 2001:db8::10
CNAMEAnother name. Not allowed at the domain’s rootwww.example.com → example.com
NSThe name servers in charge of the domainFour Route 53 servers
SOAHousekeeping for the zone. Created for you—
Alias (Route 53 only)An AWS resource, like a load balancer. Allowed at the rootexample.com → quickcart-web-alb

Never point a record at one server’s IP address. Servers get replaced and their addresses change. Point it at the load balancer, which stays put while servers come and go behind it.

A load balancer has no fixed IP address either — AWS changes them as it scales. A normal A record would go stale. An alias record fixes that: Route 53 looks up the load balancer’s current addresses every time it answers. Alias queries to AWS resources are also free.

Why not a CNAME? The root of a domain, example.com itself (called the apex), must hold the NS and SOA records. DNS rules forbid a CNAME from sharing its name with any other record, so it can’t go there. An alias can.

HTTPS and certificates

HTTPS is HTTP inside an encrypted connection, using a protocol called TLS. It does two jobs:

JobWhat it meansWithout it
EncryptionNobody between the phone and QuickCart can read or change the trafficAnyone on the same café Wi-Fi can read passwords and orders
IdentityThe phone can check it’s really talking to example.comAn attacker can pretend to be QuickCart

The identity part comes from a certificate: a file that says “this key belongs to example.com”, signed by a certificate authority that every browser and phone already trusts.

ACM: free certificates that renew themselves

ACM — AWS Certificate Manager — issues trusted certificates for free, as long as you use them on AWS services like a load balancer. Before it issues one, you prove you control the domain:

ValidationHow you prove itRenews by itself?
DNS (use this)ACM gives you a CNAME record to create. It checks the record appears in public DNSYes, as long as the record stays
EmailACM emails the domain’s contacts, and someone clicks a linkNo — someone has to click again each time

With the domain in Route 53, one button creates the validation record for you.

Where the encryption ends

The certificate goes on the load balancer, not on the servers. The load balancer decrypts each request and passes it to the servers inside the VPC. This is called TLS termination. The servers don’t handle certificates at all.

The load balancer gets two listeners — the ports it answers on:

ListenerWhat it does
HTTPS on 443Uses the certificate. Sends requests on to the app
HTTP on 80Answers every request with a 301 redirect to the same address on https://. 301 means “moved permanently”, so browsers remember it

If you don’t own a domain

A self-signed certificate is one you make yourself, signed by nobody. It’s free and instant, and the traffic is just as encrypted. But no trusted authority vouches for it, so every browser shows a warning, and apps refuse to connect.

Your own domain + ACMSelf-signed
CostA domain, roughly $10–15 a year for .com, plus $0.50 a month for the hosted zoneNothing
BrowserA padlock“Your connection is not private”
AppsConnect normallyRefuse, unless you add an exception
RenewalAutomaticYou make a new one and import it
Good forAnything customers useLearning how the pieces fit

Part 3: See it

Follow one lookup for example.com, from a customer’s phone to QuickCart’s load balancer. Then switch the registrar to Still the registrar’s — as if you created the hosted zone but forgot the last step — and try again.

Name servers set at the registrar
A DNS lookup. A customer's phone asks a DNS resolver. The resolver asks, in turn, the root servers, the .com servers, and then whichever name servers the .com servers point to: Route 53's, or the registrar's. The answer leads the phone to QuickCart's load balancer.Customer's phoneopens example.comDNS resolverrun by the networkRoot serversknow who runs .com.com serversknow each domain's name serversRoute 53 name serversyour hosted zone and its recordsRegistrar's name serversthe registrar's defaultsLoad balancerQuickCart's front door, 203.0.113.10
ReadyChoose Open example.com to follow the lookup from the phone.

What to notice: in the second run, Route 53 and its records didn’t change at all. The lookup simply never reached them. When DNS “isn’t working” after you create a hosted zone, check the name servers at the registrar first.

Part 4: Do it

You’ll put a load balancer on HTTPS, redirect HTTP to it, and — if you have a domain — give it a proper name. About 40 minutes, plus waiting for DNS.

There are two paths. Steps 1–3 and 8–9 are the same for both.

PathYou needSteps
A: your own domainA domain you control. This lesson writes example.com; use yours everywhere you see it1, 2, 3, 4, 5, 6, 8, 9, 10, 11
B: self-signedNothing extra1, 2, 3, 7, 8, 9, 11

Check the region selector at the top right says N. Virginia (us-east-1). The lab uses the default VPC, which every account has in every region, with a public subnet in each zone.

  1. Create the load balancer's security group

    In the AWS console: EC2Network & SecuritySecurity GroupsCreate security group

    FieldEnter
    Security group namequickcart-alb-sg
    DescriptionQuickCart load balancer: HTTP and HTTPS from anywhere
    VPCthe default VPC

    Under Inbound rules, choose Add rule twice:

    TypeSource
    HTTP (port 80)Anywhere-IPv4 (0.0.0.0/0)
    HTTPS (port 443)Anywhere-IPv4 (0.0.0.0/0)

    Leave the outbound rule as it is. Choose Create security group.

    You should see

    The group’s details page, with two inbound rules: ports 80 and 443 from 0.0.0.0/0.

  2. Create an empty target group

    A load balancer needs somewhere to send traffic when you create it. There are no servers in this lab, so the target group stays empty; you’ll replace its job with a fixed response in step 8.

    In the AWS console: EC2Load BalancingTarget GroupsCreate target group

    FieldEnter
    Choose a target typeInstances
    Target group namequickcart-web-tg
    Protocol : PortHTTP : 80
    VPCthe default VPC

    Leave the rest at its defaults and choose Next. Register nothing. Choose Create target group.

  3. Create the load balancer

    In the AWS console: EC2Load BalancingLoad BalancersCreate load balancer

    Under Application Load Balancer, choose Create.

    FieldEnter
    Load balancer namequickcart-web-alb
    SchemeInternet-facing
    Load balancer IP address typeIPv4
    VPCthe default VPC
    Availability Zones and subnetstick us-east-1a and us-east-1b
    Security groupsremove default, choose quickcart-alb-sg
    ListenerHTTP : 80, default action Forward to quickcart-web-tg

    Choose Create load balancer, then View load balancer.

    You should see

    State: Provisioning, changing to Active after a few minutes. Copy its DNS name — a long name ending in us-east-1.elb.amazonaws.com. This lesson calls it ALB_DNS_NAME.

  4. Path A: create the hosted zone

    If you bought your domain through Route 53, a hosted zone already exists. Skip to step 6 — creating a second one is a common mistake, below.

    In the AWS console: Route 53Hosted zonesCreate hosted zone

    FieldEnter
    Domain nameexample.com — your domain
    TypePublic hosted zone

    Choose Create hosted zone.

    You should see

    Two records already exist: an NS record listing four name servers, like ns-123.awsdns-45.com, and an SOA record. Yours have different numbers.

  5. Path A: point the registrar at Route 53

    Open your hosted zone and copy the four values from its NS record.

    In your registrar’s website, find the domain’s name servers setting. Replace whatever is there with the four Route 53 name servers, and save. Every registrar’s page looks different; search its help pages for “change name servers” or “custom nameservers”.

    Then check what the world sees, from your computer’s terminal:

    Terminal
    dig +short NS example.com
    PartWhat it means
    digask DNS a question and print the answer
    +shortprint only the answer, not the full report
    NSask for the name servers in charge of the domain
    example.comyour domain
    You should see
    ns-123.awsdns-45.com.
    ns-678.awsdns-12.net.
    ns-1024.awsdns-00.org.
    ns-1600.awsdns-10.co.uk.

    When this matches your hosted zone’s four, delegation is working. It often takes minutes, but can take up to a day or two, because resolvers may still hold the old answer until its TTL runs out.

  6. Path A: request a certificate

    In the AWS console: Certificate ManagerCertificatesRequest

    Choose Request a public certificate, then Next.

    FieldEnter
    Fully qualified domain nameexample.com
    Add another name to this certificatewww.example.com
    Validation methodDNS validation
    Key algorithmRSA 2048

    Leave anything else at its default. Choose Request.

    Open the new certificate. Its status is Pending validation. In the Domains section, choose Create records in Route 53, check both names are ticked, and choose Create records.

    You should see

    Within a few minutes — occasionally up to half an hour — Status: Issued. In the hosted zone, a new CNAME record with a long random name. Leave it there for good: ACM checks it again every time it renews the certificate.

    Now skip to step 8.

  7. Path B: make and import a self-signed certificate

    Make a certificate and its private key, in any folder on your computer:

    Terminal
    openssl req -x509 -newkey rsa:2048 -nodes -keyout quickcart-key.pem -out quickcart-cert.pem -days 30 -subj "/CN=quickcart.example.com"
    PartWhat it means
    openssl reqthe tool’s certificate-making command
    -x509make a finished, self-signed certificate, instead of a request for someone else to sign
    -newkey rsa:2048make a new 2048-bit RSA private key to go with it — a type ACM accepts
    -nodesdon’t protect the key with a password. ACM only imports unprotected keys
    -keyout quickcart-key.pemwhere to save the private key. Keep it secret
    -out quickcart-cert.pemwhere to save the certificate
    -days 30how long it lasts
    -subj "/CN=quickcart.example.com"the name it claims to be for, set here so it doesn’t ask you questions
    You should see

    A burst of dots and plus signs while the key is generated, then two new files in the folder: quickcart-key.pem and quickcart-cert.pem.

    Print the certificate, so you can copy it:

    Terminal
    cat quickcart-cert.pem
    PartWhat it means
    catprint a file’s contents
    quickcart-cert.pemthe certificate you just made
    You should see
    -----BEGIN CERTIFICATE-----
    MIIDITCCAgmgAwIBAgIUU+7pZ7yAR4jewxjumSmlJukGtrcwDQYJKoZIhvcNAQEL

    It continues for about 20 lines and ends with -----END CERTIFICATE-----. Yours has different letters.

    In the AWS console: Certificate ManagerCertificatesImport

    FieldEnter
    Certificate bodyeverything printed by cat quickcart-cert.pem, including the BEGIN and END lines
    Certificate private keyeverything in quickcart-key.pem — print it the same way
    Certificate chainleave empty. A self-signed certificate has no chain

    Choose Import. If the console shows a review page first, choose Import there too.

    You should see

    The certificate in the list, Type: Imported, Status: Issued, for quickcart.example.com.

  8. Add the HTTPS listener

    In the AWS console: EC2Load Balancersquickcart-web-albListeners and rulesAdd listener

    FieldEnter
    Protocol : PortHTTPS : 443
    Default actionReturn fixed response
    Response code200
    Content typetext/plain
    Response bodyQuickCart over HTTPS
    Security policyleave the recommended default
    Default SSL/TLS server certificateFrom ACM, then your certificate

    Choose Add.

    A real service would forward to a target group of servers here. The fixed response lets you test HTTPS without any.

    You should see

    Two listeners: HTTP:80 and HTTPS:443, the second showing your certificate.

  9. Redirect HTTP to HTTPS

    In the same Listeners and rules tab, select HTTP:80, then choose Manage listener → Edit listener.

    FieldEnter
    Default actionRedirect to URL
    Redirect toURI parts
    Protocol : PortHTTPS : 443
    Status code301 - Permanently moved

    Choose Save changes.

  10. Path A: point your domain at the load balancer

    In the AWS console: Route 53Hosted zonesexample.comCreate record

    FieldEnter
    Record nameleave empty — this is the apex, example.com itself
    Record typeA
    AliasOn
    Route traffic toAlias to Application and Classic Load Balancer
    RegionUS East (N. Virginia)
    Load balancerdualstack.quickcart-web-alb- followed by numbers — yours
    Routing policySimple routing

    Choose Create records. Do it once more with Record name www, so both names on the certificate lead somewhere.

  11. Test it

    Path A. Ask for the plain HTTP address:

    Terminal
    curl -I http://example.com
    PartWhat it means
    curlmake a web request from the terminal
    -Iprint only the response’s headers, not the page
    http://example.comyour domain, deliberately over plain HTTP
    You should see
    HTTP/1.1 301 Moved Permanently
    Server: awselb/2.0
    Location: https://example.com:443/

    There are a few more header lines; these are the ones that matter. The load balancer sent you to HTTPS. Now open https://example.com in a browser.

    You should see

    A padlock in the address bar and the text QuickCart over HTTPS. Select the padlock to see the certificate, issued by Amazon.

    Path B. Use the load balancer’s DNS name from step 3:

    Terminal
    curl https://ALB_DNS_NAME
    PartWhat it means
    curlmake a web request
    https://ALB_DNS_NAMEthe load balancer’s DNS name, over HTTPS
    You should see
    curl: (60) SSL certificate problem: self signed certificate

    The wording may differ slightly with your version of curl. Curl refused: the traffic would be encrypted, but nobody trusted vouches for the certificate. Tell curl you accept that, for this test only:

    Terminal
    curl -k https://ALB_DNS_NAME
    PartWhat it means
    curlmake a web request
    -kcarry on even though the certificate isn’t trusted. Only ever for testing
    https://ALB_DNS_NAMEthe load balancer’s DNS name, over HTTPS
    You should see
    QuickCart over HTTPS

    Open the same address in a browser. It shows Your connection is not private — that’s the trade-off from the idea. You can click through it; your customers shouldn’t have to.

  12. Clean-up step: Clean up

    The load balancer bills every hour, so delete it first.

    In the AWS console: EC2Load Balancersquickcart-web-albActionsDelete load balancer

    Type confirm and choose Delete. Then delete the rest, in this order:

    WhereDelete
    EC2 > Target Groupsquickcart-web-tg — Actions → Delete
    EC2 > Security Groupsquickcart-alb-sg — Actions → Delete security groups. If it refuses, wait a minute for the load balancer to finish deleting
    Certificate Manageryour certificate — Delete
    Route 53 > Hosted zones > example.com (path A)the two A records and the validation CNAME. Then the hosted zone itself — Delete zone

    A hosted zone can only be deleted once it holds nothing but its NS and SOA records. If you plan to keep using the domain with Route 53, keep the hosted zone instead, at $0.50 a month.

    For path B, delete the two .pem files from your computer.

    You should see

    No load balancer, target group, certificate or hosted zone left. If you bought a domain just for this, it stays yours until it expires; turn off auto-renew at the registrar if you don’t want it.

Part 5: Check yourself

QuickCart created a hosted zone in Route 53 with the right records, but example.com still shows the registrar's parking page. What is the most likely cause?

Why does QuickCart point example.com at the load balancer with an alias record rather than a CNAME?

How does ACM's DNS validation prove you own example.com?

What is the trade-off of a self-signed certificate on the load balancer?

Someone types http://example.com. What should the load balancer's port 80 listener do?

QuickCart changes a record's value, but some customers still reach the old address for an hour. Why?

Part 6: Cheat sheet

On one card
TermIn one line
DNSTurns names into IP addresses, by a chain of servers
ResolverAsks on your behalf, and caches answers
TTLHow many seconds an answer may be cached
RegistrarWhere you bought the domain. Sets its name servers
Hosted zoneWhere a domain’s records live in Route 53. $0.50 a month
NS recordThe four name servers in charge. Must match at the registrar
A / AAAAName → IPv4 / IPv6 address
CNAMEName → another name. Never at the apex
AliasRoute 53 only. Name → AWS resource, allowed at the apex
ACMFree trusted certificates for load balancers. DNS validation renews itself
TLS terminationThe load balancer decrypts; servers don’t handle certificates
Port 80 listener301 redirect to HTTPS
Self-signedEncrypted, but untrusted. For learning only
DNS not working?dig +short NS example.com — does it match the hosted zone?

Finished the build and the quiz? Mark it done to fill in its stop on the route map.