Module 2 · Create and deploy your first CDK appBuild

Write your first stack

Every construct takes the same three arguments. Add your first one — a versioned S3 bucket — and watch it synthesize.

Every construct you'll ever write in CDK — a bucket, a table, a function, all of it — takes the same three arguments.

scope, id, and props

export class FirstStack extends Construct {
  constructor(scope: Construct, id: string) {
    super(scope, id);
    // resources go here
  }
}
  • scope — the parent construct this one lives inside. Every resource in a CDK app sits somewhere in a tree; scope is that resource's position in it.
  • id — a name unique within scope, used to tell resources apart and to derive the logical IDs CloudFormation actually uses.
  • super(scope, id) — calls the parent class's constructor, wiring your construct into that tree before you add anything to it.

Every resource you create inside — new Bucket(this, 'MyFirstBucket', ...) — follows the exact same shape: this as the scope, a string id, then whatever properties that resource needs.

Your task

Add a single S3 bucket, MyFirstBucket, with versioning turned on.

new Bucket(this, 'MyFirstBucket', {
  versioned: true,
});

Run the synthesizer and you'll see this exact construct turn into a real AWS::S3::Bucket resource in the CloudFormation output — the same translation that happens whether you deploy it from CloudSynth's sandbox or, in the next lesson, from your own machine.

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