Skip to main content
Welcome! In this demo we’ll walk through creating a simple AWS CDK (v2) project in Python that deploys an S3 bucket. This guide covers prerequisites, project initialization, adding an S3 construct, bootstrapping, synthesizing, deploying, and verifying the results in the AWS Console.

Prerequisites

Before you begin, ensure you have the following installed and configured: If you need the AWS CLI, follow the official installation documentation. Example screenshot of the AWS CLI install page:
A screenshot of the AWS documentation page titled "AWS CLI install instructions" with expandable sections for Linux, macOS, and Windows. The dark-themed browser window shows multiple tabs open and a sidebar navigation for the AWS Command Line Interface user guide.
Use nvm to install and switch Node.js versions (macOS/Linux example):
Install the AWS CDK CLI globally:

Install Python CDK libraries (CDK v2)

CDK v2 consolidates constructs into aws-cdk-lib and uses a separate constructs package:
In CDK v2 service constructs (for example, S3) are included in aws-cdk-lib. You do not need separate per-service pip packages such as aws-cdk.aws-s3.

Configure AWS credentials

Configure your AWS CLI credentials (do not paste real credentials in shared docs). Replace the placeholders with your actual keys when running locally:

Create the CDK project

  1. Open a terminal and create a project folder.
  2. Initialize a Python CDK app:
cdk init will create a standard project layout (example files you should see in your editor):
  • app.py — CDK app entrypoint
  • cdk.json — CDK CLI configuration
  • requirements.txt or virtualenv setup — Python dependencies
  • lib/ — folder containing your stack implementation file(s)
Example VS Code view of the generated project:
A screenshot of Visual Studio Code with the Explorer open, showing a "cdk-demo" project folder and listed files (app.py, cdk.json, README.md, etc.). The main editor area is empty with a faint VS Code logo visible.

Add an S3 bucket to your stack

Open the generated stack file in the lib/ folder (filename will match your project). Replace or modify the generated stack content to import S3 and create a bucket. Example stack implementation:
Key notes:
  • aws_s3 as s3 is the S3 construct namespace.
  • The second argument to s3.Bucket is the construct ID (logical name used in the synthesized CloudFormation template).
  • If you need a deterministic bucket name, supply the bucket_name property (be mindful of global uniqueness for S3 bucket names).

Bootstrap the environment

Before deploying, bootstrap your target environment. Bootstrapping provisions resources (an S3 staging bucket and deployment roles) that the CDK needs to perform deployments in the account/region.
Example output (condensed):
Bootstrapping requires IAM permissions to create the bootstrap resources. During bootstrap you often need elevated permissions (for example, Administrator). After bootstrapping you can restrict deploy-time IAM permissions following least-privilege practices.

Synthesize the CloudFormation template

To inspect the CloudFormation template the CDK generates, run:
This writes the synthesized template to stdout and to the cdk.out directory. Review it to confirm resources and properties prior to deployment.

Deploy the stack

When ready, deploy using:
The CDK synthesizes the template and uses CloudFormation to create or update resources. Example output (condensed):

Useful CDK commands

Verify in the AWS Console

Confirm the CloudFormation stack shows as CREATE_COMPLETE / UPDATE_COMPLETE:
A screenshot of the AWS CloudFormation "Stacks" console showing two stacks (CdkDemoStack and CDKToolkit) with statuses "UPDATE_COMPLETE" and "CREATE_COMPLETE." The page includes controls like Create stack, Delete stack, and filters for stack status.
Open the S3 console to confirm your bucket was created in the deployed region:
A screenshot of the AWS Amazon S3 console showing the "General purpose buckets" view with a list of S3 bucket names. The page shows controls like "Create bucket," "Copy ARN," "Empty," and "Delete."

Next steps

You now have a CDK project that provisions an S3 bucket. From here you can:
  • Extend the stack with more AWS resources (Lambda, DynamoDB, VPC, etc.).
  • Configure bucket options: versioning, encryption, lifecycle rules, public access block.
  • Add unit tests for your CDK constructs.
  • Integrate with CI/CD pipelines to automate synth/deploy.
References:

Watch Video