BucketDeployment uploads real files at deploy time — the part the console lab did for you invisibly.
A bucket configured for hosting and open for public reads still has no content in it — an empty bucket serves nothing. Real files need to actually land in the bucket somehow.
BucketDeployment (from aws-cdk-lib/aws-s3-deployment) uploads
content to a bucket as part of cdk deploy itself — no separate manual step, and it
re-runs automatically whenever the content changes. It takes a
destinationBucket and one or more sources.
Heads up:
Source.asset('./some-folder')is the version you'd use in a real project — it zips up a real directory on disk and uploads it. That doesn't work here: this browser sandbox only ever receives the single file of code you write, never a folder of real content sitting next to it. UseSource.data(...)instead — it uploads an inline string, no real directory required, which is exactly what a synth-and-assert-only sandbox can actually support.
Add a BucketDeployment pointed at your bucket, using Source.data(...)
to upload an index.html with some real content in it. BucketDeployment and
Source aren't imported yet — they come from a separate module,
aws-cdk-lib/aws-s3-deployment, not
aws-cdk-lib/aws-s3 where Bucket lives.
import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment';
new BucketDeployment(this, 'DeploySite', {
sources: [Source.data('index.html', '<h1>Hello!</h1>')],
destinationBucket: bucket,
});Locked
This exercise builds on Granting public read access — run synth & validate there until every assertion passes, then this code will unlock.
Go to Granting public read access