How I built and host this blog
A static Next.js site on S3 and CloudFront. Terraform creates all of it, and GitHub Actions deploys it with no stored keys. It costs less than $1 a month. Four things broke on the way.
On this page
This site is a static Next.js export. The files are in a private S3 bucket, and CloudFront serves them. Terraform creates every AWS resource. When I push to main, the site updates in about a minute. The AWS cost is less than $1 a month.
An AI coding assistant wrote most of the code. I made the design and the decisions, and I reviewed every Terraform plan before it ran. This post is about those decisions and about the things that broke.
The first plan was wrong
The first design used Payload CMS and a Postgres database on Azure. It had an admin panel, a rich-text editor and drafts in the database. It looked like the right setup.
It was the wrong fit. Payload needs a server and a database that run all day. This site changes only a few times a month. I wanted the hosting cost to be close to zero. So I stopped that design before I wrote any infrastructure.
| Option | What runs all the time | Monthly cost |
|---|---|---|
| Payload + Postgres on Azure | App server, database | ~$35 |
| Static export on S3 + CloudFront | Nothing | < $1 |
The $35 is an estimate. I priced the smallest setup in Central India, at Azure list prices in November 2026:
- App Service B1 Linux plan: about $13
- PostgreSQL Flexible Server B1ms: about $18
- 32 GB of database storage: about $4
I did not build it, so I have no real bill.
Each post is now an MDX file in the repo. MDX is Markdown that can also contain components. To publish a post, I push it with git. To keep a post as a draft, I set draft: true in its frontmatter. The build stops if a published file still contains a TODO placeholder.
Why AWS and not Azure
Most of my day-to-day work is on Azure. Azure Static Web Apps has a free tier, and it would host this site for $0.
I chose AWS on purpose. Many of the engineers I write for run their sites on S3 and CloudFront. So this is a setup they know and can copy. It also gives me a public, working AWS project next to my Azure work. Under $1 a month is a fair price for that.
The setup
- State: A separate Terraform root creates the S3 bucket for Terraform state. The bucket has versioning, encryption and HTTPS-only access. S3 also locks the state, so two runs cannot change it at the same time.
- Site bucket: The bucket is private. CloudFront reads it through Origin Access Control (OAC). The bucket has no public URL.
- CloudFront: It uses HTTP/2 and HTTP/3, and TLS 1.2 at minimum. The ACM certificate is in
us-east-1, because CloudFront reads certificates only from that region. A response headers policy adds HSTS for one year,nosniff,SAMEORIGINand a strict referrer policy. - DNS: A Route 53 hosted zone has A and AAAA alias records. A CAA record lets only Amazon issue certificates for the domain.
- Budget: An AWS budget of $5 a month watches the project tag. It sends an email at 80% of actual spend and at 100% of forecast spend.
Deploys with no AWS keys
GitHub Actions signs in to AWS with OIDC (OpenID Connect). GitHub gives the workflow a short-lived token. AWS checks the token and gives back a session for the deploy role. The repo stores no AWS access keys.
The deploy role can do three things only:
- List the files in the site bucket.
- Write and delete files in the site bucket.
- Clear the cache of this one CloudFront distribution.
The workflow runs the lint, the CloudFront function tests and the build. Then it uploads the files in three steps:
# 1. Hashed assets first. Browsers keep them for a year.
$ aws s3 sync out/_next/static s3://$BUCKET/_next/static \
--cache-control "public,max-age=31536000,immutable"
# 2. HTML, RSS and images. Browsers check for a new copy on every visit.
$ aws s3 sync out s3://$BUCKET --delete --exclude "_next/static/*" \
--cache-control "public,max-age=0,must-revalidate"
# 3. Now delete the old hashed assets.
$ aws s3 sync out/_next/static s3://$BUCKET/_next/static --deleteThe order is important. The new assets go up before the HTML that uses them. The old assets go away only after no page uses them. So a visitor never gets a page with missing CSS during a deploy. If a step fails, the live site does not change.
What broke
AWS denied the first deploy
The trust policy of the deploy role checks the sub claim in the GitHub token. The sub claim tells AWS which repo and branch the token comes from. I used the name-only format that most tutorials show:
values = ["repo:owner/repo:ref:refs/heads/main"]The lint and the build passed. Then the sign-in step failed:
Assuming role with OIDC
Retry AssumeRole: attempt 1 of 12 failed: Could not assume role with OIDC:
Not authorized to perform sts:AssumeRoleWithWebIdentity. Retrying after 45ms.
# ... attempts 2 to 11 fail the same way, with longer waits ...
Retry AssumeRole: reached max retries (12); giving up.
Error: Could not assume role with OIDC:
Not authorized to perform sts:AssumeRoleWithWebIdentityThe action tried 12 times in about a minute. A wrong trust policy does not fix itself, so the retries only made the failure slower.
The message also does not say which condition failed. AWS gives the same "Not authorized" message for every failed condition, so an attacker cannot learn the policy from the errors. That is good for security, but it makes the cause hard to find.
The cause was a change at GitHub. In 2026, GitHub added the owner ID and the repo ID to the sub claim. Repos created after 15 July 2026 get this format by default. My repo was new, so its tokens looked like this:
sub: repo:owner@<owner-id>/repo@<repo-id>:ref:refs/heads/mainAWS compared this text with the text in my policy. They were different, so AWS denied the sign-in.
I put the IDs in the trust condition, and the deploy worked. This rule is also safer. If someone deletes the repo and makes a new one with the same name, the new repo gets new IDs. It cannot use the deploy role.
AWS did not register the domain
I wanted to register the domain in Route 53. The request failed, and the Route 53 console showed only this message:
Status: Failed
We can't finish registering your domain. Contact AWS Support
at <support case link> for further information.The message gives no reason. I think the cause is billing, but I am not sure. AISPL, the Indian AWS company, bills this account. Domain registration may not be available for those accounts.
I did not open a support case. I bought the domain at GoDaddy instead, for two reasons:
- Support would be slow. AWS, like many other providers, now answers new support cases first with an AI agent. In my experience, those first replies do not help with an account problem like this one. A person looks at the case only later. I wanted the domain that day, not after a long back-and-forth.
- GoDaddy was cheaper. The first-year price at GoDaddy was lower than the Route 53 price. So the failed registration also saved me some money.
This choice has a cost. The domain and its DNS are now with two providers. Terraform manages the Route 53 zone, but not GoDaddy. I set the GoDaddy name servers by hand, once, so that they point to the Route 53 zone.
That makes the zone hard to replace. A new zone gets new name servers, and the domain stops working until I change them at GoDaddy again. So the zone has prevent_destroy in Terraform, and a terraform destroy cannot delete it by accident.
Renewal prices are often higher than the first-year price. I will compare the GoDaddy and Route 53 prices again before the renewal. If Route 53 is cheaper and AWS allows the transfer for this account, I can move the domain there.
The OIDC provider was already there
AWS allows one OIDC provider for each URL in an account. Another project in the same account already owned the GitHub provider. So this project reads the provider with a data source, and does not create it.
This makes one project depend on the other. If the other project deletes the provider, deploys here fail with No OpenIDConnect provider found. A comment above the data source gives this error and the steps to fix it.
S3 did not serve folder pages
A static export writes pages like /about/index.html. With a private bucket, a request for /about/ fails, because S3 serves only exact file names.
A small CloudFront function changes each request:
- It changes
/about/to/about/index.html. - It sends a 301 redirect from
/aboutto/about/. It keeps the query string, because the tag filter uses?tag=. - It sends a 301 redirect from every other host to
https://porvinder.com. Examples arewwwand the*.cloudfront.netaddress. So search engines see only one copy of each page.
The function has its own tests. The deploy runs them before the build.
Problems with the static export
Next.js caused three smaller problems:
- An empty
generateStaticParamsstops the build. At launch, every post was a draft. So the list of post pages was empty, and the export failed. Now each dynamic route returns one placeholder page that shows the 404 page. It stays until real content exists. - The link-preview images had no file extension. The built-in
opengraph-imageconvention writes the file without.pngin a static export. Then S3 does not know that the file is an image. I moved the images to plainog.pngroutes. - The dev server did not show CSS changes. I deleted the Turbopack Tailwind loader from the config and used plain PostCSS. Then the changes showed.
Cost
| Item | Monthly |
|---|---|
| Route 53 hosted zone | $0.50 |
| CloudFront and CloudFront Functions | $0 |
| ACM certificate | $0 |
| S3 storage and requests | < $0.01 |
| Total in AWS | ~$0.50 |
Most of the stack costs nothing at this traffic:
- CloudFront has a free tier that does not end after 12 months. Each month, the first 1 TB of data transfer, 10 million requests and 2 million CloudFront Functions calls are free. If a cloud architect's notes on daily work ever pass 10 million requests a month, I will be too happy to worry about the bill.
- ACM does not charge for public certificates that CloudFront uses.
- S3 stores a few megabytes, and CloudFront caches most requests. So the S3 cost is a fraction of a cent.
The only fixed cost is the Route 53 hosted zone. DNS queries also cost money, but at this traffic they cost less than one cent. These numbers are estimates from the AWS price lists. I will update them with the real bill after the first full month.
The domain at GoDaddy costs extra.
What I would change
- Give the OIDC provider its own Terraform root. Today one project owns the GitHub OIDC provider, and this project only reads it. A small, separate root for shared account resources would end that link. Then neither project can break the deploys of the other.
- Decide how the site runs before I design anything else. I designed the Payload and Postgres setup before I asked how much it would cost to run. Static hosting was the right answer all along. A short check of hosting cost first would have saved that design time.
- Check the current documentation, not the tutorials. The OIDC error came from an older format that most tutorials still show. The current GitHub documentation already showed the new format. Five minutes with the official page would have saved a failed deploy.
