Lesson 02Build

Provisioning a bucket for static hosting

One CDK bucket, two properties — index and error documents, no console click-through required.

A hosting-enabled bucket gets a dedicated URL: http://<bucketname>.s3-website.eu-central-1.amazonaws.com. A request to that URL makes S3 retrieve the bucket's designated root object — usually index.html — and serve it. No traditional web server to patch, scale, or keep running.

Heads up: that URL is http://, not https:// — the S3 website endpoint doesn't support TLS at all. (It's also region-specific in its own way: this dot-separated s3-website.<region>.amazonaws.com format is what regions added from 2014 onward use, including this platform's own eu-central-1 — the handful of original 2006-2013 regions use a dash instead, s3-website-<region>.amazonaws.com.)

The CDK way

In CDK, "create the bucket" and "configure it for website hosting" are the same statement — a single constructor call, not a separate step. Bucket (imported from aws-cdk-lib/aws-s3 — already imported in the starter) takes websiteIndexDocument and websiteErrorDocument right in its constructor — there's no separate "enable hosting" step to remember.

Your task

On the right, the starter construct creates a bucket but never enables hosting. Set websiteIndexDocument to "index.html" and websiteErrorDocument to "error.html", then run the synthesizer.

Tip: error.html is what S3 serves when a request 404s — the same role a custom 404 page plays on any web server.

2 assertions · cdk-nag AwsSolutions ruleset

Not run yet

Edit the construct, then run synth & validate to check your work.

Validation · TypeScriptNot run · 2 pending
Assertion 1
Assertion 2