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:
- Route 53 to handle DNS for
sonkar.dev - ACM certificate so CloudFront can serve HTTPS
- CloudFront updated with your domain + certificate
Part 1 — Route 53 Hosted Zone
Step 1: Create a hosted zone
- AWS Console → Route 53 → Hosted zones → Create hosted zone
- Domain name:
sonkar.dev - Type: Public hosted zone
- 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
- Log into name.com → My Domains → sonkar.dev → Nameservers
- Select Use Custom Nameservers
- Delete the existing name.com nameservers
- Add each of the 4 Route 53 nameservers (without the trailing dot if shown)
- 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 inus-east-1.
- AWS Console → top-right region selector → switch to
us-east-1 (N. Virginia) - Go to Certificate Manager (ACM) → Request a certificate
- Select Request a public certificate → Next
- Domain names — add both:
sonkar.devwww.sonkar.dev
- Validation method: DNS validation
- Click Request
Step 4: Validate via Route 53 (one click)
- Click into the certificate — status shows Pending validation
- Expand each domain listed under Domains
- Click Create records in Route 53 (button appears for each domain, or once for all)
- AWS automatically adds the CNAME validation records to your Route 53 hosted zone
- 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
- CloudFront → Distributions → click your distribution
- General tab → click Edit
- Alternate domain names (CNAMEs): click Add item twice and add:
sonkar.devwww.sonkar.dev
- Custom SSL certificate: click the field and select the
sonkar.devcertificate you just issued- If it doesn't appear, confirm you're looking at a certificate in
us-east-1
- If it doesn't appear, confirm you're looking at a certificate in
- 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):
- Route 53 → Hosted zones →
sonkar.dev→ Create record - Record name: leave blank (this is the root
@) - Record type:
A - Toggle Alias to ON
- Route traffic to: Alias to CloudFront distribution
- Distribution: select your CloudFront distribution from the dropdown
- Click Create records
Record 2 — www subdomain:
- Create record again
- Record name:
www - Record type:
A - Toggle Alias to ON
- Route traffic to: Alias to CloudFront distribution
- Select the same distribution
- 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.devloads correctly -
https://www.sonkar.devloads correctly - HTTPS padlock is present on both
-
http://sonkar.devredirects tohttps://(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:
npm run build→ uploadout/to S3- 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
wwwA 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.