Skip to main content

Static Website

This page builds a static website and puts it on the internet. By the end you will have two HTML pages served out of an S3 bucket, on a public URL you can open in a browser, and you will have changed one of them and watched the change go out.

The project you start from describes the site in four parts: an app that holds everything together, the AWS account it goes into, the region inside that account, and the website itself.

Costs

A bucket holding two small HTML files costs a fraction of a cent a month. The teardown at the end removes it.

Create the project​

npx @quadnix/octo-build create-app -n hello-website
cd hello-website
mkdir website

create-app writes an octo.yaml with an app, an account and a region. website/ holds the two pages, index.html and error.html, which you write yourself, and whatever you put in that folder is uploaded on the next run:

website/index.html
<!doctype html>
<html><body><h1>Hello from Octo</h1></body></html>
website/error.html
<!doctype html>
<html><body><h1>That page does not exist</h1></body></html>

Make it yours​

Open octo.yaml. Its env block holds the account number, and you add the bucket name as a second value:

octo.yaml
env:
- key: AWS_ACCOUNT_ID
kind: string
value: "123456789012" # your AWS account number
- key: AWS_S3_WEBSITE_BUCKET_NAME
kind: string
value: octo-hello-website # a name of your own

S3 bucket names are shared by every AWS customer, so pick one nobody else is likely to use. octo-hello-website is the name this page was captured with, and it is already taken.

If your credentials live under a profile other than default, change profile in the terraform block as well.

Then replace the imports and modules with the four parts from the diagram. Each entry under modules loads one module and gives it its inputs:

octo.yaml
imports:
- className: SimpleAppModule
importPath: "@quadnix/octo-aws-cdk/modules/app/simple-app"
- className: AwsIniAccountModule
importPath: "@quadnix/octo-aws-cdk/modules/account/aws-ini-account"
- className: AwsServerlessRegionModule
importPath: "@quadnix/octo-aws-cdk/modules/region/aws-serverless-region"
- className: AwsS3StaticWebsiteServiceModule
importPath: "@quadnix/octo-aws-cdk/modules/service/aws-s3-static-website-service"

modules:
- moduleId: app-module
moduleClass: SimpleAppModule
moduleInputs:
name: aws-s3-website

- moduleId: account-module
moduleClass: AwsIniAccountModule
moduleInputs:
accountId: "${env.AWS_ACCOUNT_ID}"
app: "${{app-module.model.app}}"

- moduleId: region-module
moduleClass: AwsServerlessRegionModule
moduleInputs:
account: "${{account-module.model.account}}"
name: aws-s3-website
regionId: aws-us-east-1

- moduleId: s3-website-service-module
moduleClass: AwsS3StaticWebsiteServiceModule
moduleInputs:
bucketName: "${env.AWS_S3_WEBSITE_BUCKET_NAME}"
directoryPath: website
region: "${{region-module.model.region}}"

${env.AWS_ACCOUNT_ID} reads a value from the env block. ${{app-module.model.app}} hands one module what another one built, here the app, and those references are what join the four entries into the shape in the diagram. The last module does the real work: it creates the bucket, uploads the folder, and makes the result public.

Deploy it​

npm run octo:generate
npm run octo:validate

npm run octo:lock
npm run octo:apply
npm run octo:commit

generate turns octo.yaml into Terraform, in a folder called .octo-tf. It needs no credentials and touches nothing outside your project.

validate plans that Terraform and reports what it would do, grouped under the piece of intent that asked for it. This is the first command that reaches AWS, and it creates nothing:

aws-s3-website — octo validate — changes (approximate)
2026-09-29 01:14:01 UTC · 4ms octo · 4.0s terraform

You added service=octo-hello-website-s3-static-website. That creates 6 new things.
- 0 destroy ± 0 replace + 6 create ~ 0 update

Your intent changed, so each folder was planned on its own against its dependencies' last
applied outputs. A cross-folder consequence of this change is invisible until apply. This
report can both understate what apply will do and overstate drift.

WHAT WILL CHANGE
+ added service=octo-hello-website-s3-static-website [service=octo-hello-website-s3-static-website,region=aws-s3-website,account=123456789012,app=aws-s3-website | s3-website-service-module | +6]
+ bucket-octo-hello-website
+ aws_s3_bucket_policy.bucket-octo-hello-website_website_bucket_policy
+ aws_s3_bucket_public_access_block.bucket-octo-hello-website_website_bucket_public_access
+ aws_s3_bucket_website_configuration.bucket-octo-hello-website_website_bucket_config
+ aws_s3_bucket.bucket-octo-hello-website_website_bucket
+ aws_s3_object.bucket-octo-hello-website_file_errorhtml
+ aws_s3_object.bucket-octo-hello-website_file_indexhtml

Read it from the top down. You added one thing, the website, and serving a website from S3 takes six Terraform resources: the bucket, its website settings, an opened public access block, a policy letting anyone read it, and one object for each of your two pages. You asked for the first line; the module knew the rest. Reading a Validate Report covers every part of a report.

lock takes a lock on the app, so that nobody else can change it while you do. apply creates the infrastructure, which takes under a minute here. It does not stop to ask, because you have already read the report. commit then records what AWS created, ARNs and all, so that the next run knows the bucket exists, and releases the lock. The Lifecycle explains why these are separate steps.

Open it​

The site answers on the bucket's S3 website address, which is the bucket name and the region:

http://octo-hello-website.s3-website-us-east-1.amazonaws.com

Ask for a page that does not exist and error.html comes back. The bucket's Properties tab in the S3 console shows the exact address, should yours differ.

The address is plain HTTP, because S3 website hosting does not do HTTPS. Website on CloudFront serves the same files over HTTPS from a bucket nobody else can read.

Change a page​

Add a line to website/index.html:

website/index.html
<h1>Hello from hello-website</h1>
<p>Deployed with Octo.</p>

and run generate and validate again:

You changed service=octo-hello-website-s3-static-website. That updates 1 thing in place.
- 0 destroy ± 0 replace + 0 create ~ 1 update

WHAT WILL CHANGE
~ changed service=octo-hello-website-s3-static-website [service=octo-hello-website-s3-static-website,region=aws-s3-website,account=123456789012,app=aws-s3-website | s3-website-service-module | ~1]
~ bucket-octo-hello-website
~ aws_s3_object.bucket-octo-hello-website_file_indexhtml
etag: 43d707bebe2010beda60ccf02d98b646 → 0115cb00cb5d5142657ee12ce20c0bad

One file changed, so one upload is planned, and the bucket and everything else is left alone. Run lock, apply and commit, reload the page, and the new line is there.

When it fails​

validate fails before it plans anything when your credentials are missing. Check that aws sts get-caller-identity --profile <your profile> prints the account number you put in AWS_ACCOUNT_ID.

apply fails with BucketAlreadyExists when somebody else owns the bucket name. A plan cannot know that in advance. Pick another name and start again from generate.

The site answers 403 to everyone, after an apply that succeeded, when an administrator has turned on S3 Block Public Access for the whole account. That setting overrides the bucket's own, and it is usually on for a reason. Use Website on CloudFront instead, which needs no public bucket.

Tear it down​

You remove infrastructure by removing it from octo.yaml. Comment out the region and the website, leaving the app and the account:

octo.yaml
  #- moduleId: region-module
# ...

#- moduleId: s3-website-service-module
# ...
npm run octo:generate

npm run octo:lock
npm run octo:apply -- --auto-approve
npm run octo:commit

apply refuses to destroy anything unless you say so, and prints what it would remove. Here that is the whole website, so --auto-approve lets all of it through. Destroying Infrastructure covers approving one destroy at a time.