Skip to content
← Back to Notes

Setting Up Custom Domain

Starting point: CloudFront distribution is live at a *.cloudfront.net URL (from the previous note). You have just purchased sonkar.dev on name.com.
End point: https://sonkar.dev and https://www.sonkar.dev both serve your site.


How this works

Browser → sonkar.dev
  → Route 53 (DNS) → resolves to CloudFront
    → CloudFront → serves from S3

You need three things:

  1. Route 53 to handle DNS for sonkar.dev
  2. ACM certificate so CloudFront can serve HTTPS
  3. CloudFront updated with your domain + certificate

Part 1 — Route 53 Hosted Zone

Step 1: Create a hosted zone

  1. AWS Console → Route 53 → Hosted zones → Create hosted zone
  2. Domain name: sonkar.dev
  3. Type: Public hosted zone
  4. Click Create hosted zone

Route 53 creates the zone and immediately gives you 4 nameserver (NS) records. They look like:

ns-382.awsdns-47.com
ns-1543.awsdns-00.co.uk
ns-784.awsdns-33.net
ns-1320.awsdns-37.org

Copy all four. You'll need them in the next step.


Step 2: Point name.com to Route 53

  1. Log into name.com → My Domains → sonkar.dev → Nameservers
  2. Select Use Custom Nameservers
  3. Delete the existing name.com nameservers
  4. Add each of the 4 Route 53 nameservers (without the trailing dot if shown)
  5. Save

DNS propagation takes anywhere from a few minutes to 48 hours. Usually under 30 minutes.


✅ Checkpoint 1 — Verify nameservers propagated

Go to dnschecker.org → enter sonkar.dev → select NS record type.

Once you see your 4 Route 53 nameservers appearing globally, proceed. If you still see name.com nameservers, wait longer.


Part 2 — ACM SSL Certificate

Step 3: Request a certificate (region is critical)

CloudFront only accepts ACM certificates from us-east-1 (N. Virginia). If your S3 bucket is in Mumbai or any other region, it does not matter — the certificate must be in us-east-1.

  1. AWS Console → top-right region selector → switch to us-east-1 (N. Virginia)
  2. Go to Certificate Manager (ACM) → Request a certificate
  3. Select Request a public certificate → Next
  4. Domain names — add both:
    • sonkar.dev
    • www.sonkar.dev
  5. Validation method: DNS validation
  6. Click Request

Step 4: Validate via Route 53 (one click)

  1. Click into the certificate — status shows Pending validation
  2. Expand each domain listed under Domains
  3. Click Create records in Route 53 (button appears for each domain, or once for all)
  4. AWS automatically adds the CNAME validation records to your Route 53 hosted zone
  5. Wait — certificate status changes to Issued in about 5–10 minutes

✅ Checkpoint 2 — Certificate issued

In ACM, the certificate status must show Issued before moving on. If it stays Pending after 30 minutes, the nameservers likely haven't propagated yet — revisit Checkpoint 1.


Part 3 — Update CloudFront

Step 5: Add your domain to the distribution

  1. CloudFront → Distributions → click your distribution
  2. General tab → click Edit
  3. Alternate domain names (CNAMEs): click Add item twice and add:
    • sonkar.dev
    • www.sonkar.dev
  4. Custom SSL certificate: click the field and select the sonkar.dev certificate you just issued
    • If it doesn't appear, confirm you're looking at a certificate in us-east-1
  5. Click Save changes

The distribution status changes to Deploying — wait until it returns to Enabled (5–10 minutes).


Part 4 — Route 53 DNS Records

Step 6: Create A records pointing to CloudFront

Route 53 uses Alias records for CloudFront — these are free and update automatically if the CloudFront IP changes.

Record 1 — root domain (sonkar.dev):

  1. Route 53 → Hosted zones → sonkar.devCreate record
  2. Record name: leave blank (this is the root @)
  3. Record type: A
  4. Toggle Alias to ON
  5. Route traffic to: Alias to CloudFront distribution
  6. Distribution: select your CloudFront distribution from the dropdown
  7. Click Create records

Record 2 — www subdomain:

  1. Create record again
  2. Record name: www
  3. Record type: A
  4. Toggle Alias to ON
  5. Route traffic to: Alias to CloudFront distribution
  6. Select the same distribution
  7. Click Create records

✅ Checkpoint 3 — Verify DNS records

In Route 53 → sonkar.dev hosted zone, you should now see:

Name Type Value
sonkar.dev NS 4 Route 53 nameservers
sonkar.dev SOA (auto-generated)
sonkar.dev A (Alias) CloudFront distribution
www.sonkar.dev A (Alias) CloudFront distribution
_acme-challenge... CNAME ACM validation record

✅ Checkpoint 4 — Site is live

Visit both URLs in a fresh browser (or use a private window to avoid cache):

  • https://sonkar.dev loads correctly
  • https://www.sonkar.dev loads correctly
  • HTTPS padlock is present on both
  • http://sonkar.dev redirects to https:// (handled by CloudFront's "Redirect HTTP to HTTPS" setting)
  • A note article URL works when typed directly (e.g. https://sonkar.dev/notes/bloom-filters/)

If HTTPS shows a certificate warning, the ACM certificate might not be attached — re-check Step 5.


Redeployment stays the same

The deploy process from the previous note does not change. You still:

  1. npm run build → upload out/ to S3
  2. Invalidate CloudFront cache with /*

sonkar.dev will serve the new version automatically.


Optional: redirect www → root (or vice versa)

Currently both sonkar.dev and www.sonkar.dev serve the same content independently — no redirect between them. This is fine for most purposes.

If you want www.sonkar.dev to permanently redirect to sonkar.dev:

  • Create a second S3 bucket named exactly www.sonkar.dev
  • Enable static website hosting on it → set redirect to sonkar.dev
  • Create a second CloudFront distribution pointing to that bucket's website endpoint
  • Update the www A record to point to this second distribution

This is optional — having both serve content with a canonical URL tag (already set in your metadata) is sufficient for SEO.