AWS CDK Instructions

This section provides instructions for using AWS CDK with the solution.

Contents

Prerequisites

  1. Install Python on your local computer.
  2. Install Node.js on your local computer.
    • CDK uses Node.js under the hood; the code will be in Python for this application.
  3. Install CDK on your local computer.
    sudo npm install -g aws-cdk
    

Setup Instructions

The cdk.json file provides instructions for the AWS CDK toolkit to execute your application.

This project is set up like a standard Python project. The initialization process below will create a Python runtime virtual environment within this project, stored under the .venv directory. To create the virtual environment, the instructions assume that there is a python3 (or python for Windows) executable in your path with access to the venv package.

To create a Python runtime virtual environment on MacOS and Linux:

python3 -m venv .venv

After the initialization process completes and the virtual environment is created, you can use the following step to activate your virtual environment:

source .venv/bin/activate

If you are using a Windows platform, activate the virtual environment as shown below:

% .venv\Scripts\activate.bat

Once the virtual environment is activated, you can install the required dependencies.

pip install -r requirements.txt

At this point you can now synthesize the CloudFormation template using AWS CDK for this application.

cdk synth

To add additional dependencies, for example other CDK libraries, add them to the requirements.txt or requirements-dev.txt files and rerun the pip install -r requirements.txt command.


Useful Commands

cdk synthOutputs the synthesized CloudFormation template
cdk deployDeploys this stack to your default AWS account and Region
cdk diffCompares deployed stack with current application state
cdk docsOpens AWS CDK documentation

For more details refer to the AWS CDK CLI Reference.


Visual Studio Code Debugging

To configure Visual Studio Code for debugging an AWS CDK application in Python, use the following launch configuration in launch.json:

 {
	"version": "0.2.0",
	"configurations": [
		{
			"name": "CDK Synth",
			"type": "python",
			"request": "launch",
			"program": "app.py",
			"console": "integratedTerminal",
			"justMyCode": true
		}
	]
}

Back to top

Copyright Amazon.com and its affiliates; all rights reserved. This file is Amazon Web Services Content and may not be duplicated or distributed without permission.

Page last modified: Sep 26 2024.