AWS CDK with Python

Python is the second most popular language of AWS CDK, after TypeScript. Although AWS CDK technically supports multiple languages, the command-line tool and the libraries of AWS CDK are all written in TypeScript. Thus, if you want to run the AWS CDK command-line tool, you still need to install Node.js. Also, under the hood AWS CDK will use Node.js to run the CDK code that is written in TypeScript.

For the most part it will be transparent to you that AWS CDK is written in TypeScript, but you may see some errors that may leak TypeScript info at times, and some Python code tricks may not work with AWs CDK components.

The Python ecosystem has many different tools for package management, dependency management, testing, linting, coe formatting etc. In this book we will use a specific set of tools:

There is nothing stopping you from using other tools if you prefer, but relevant descriptions will use these mentioned tools.

Python version

We will be using the latest version at the time of writing, which is Python 3.13. You can use earlier versions as well, and if you use Python 3.11 or later, the code should be identical.

Type hints

Throughout the book, you will see that we use types with the Python code we write. This is entirely optional, but it will be beneficial to have in place, since our infrastructure code will be very much about specifying data fields that have well-defined types.

You can read about Python type hints in many places, for example here and here.

We will also be using TypedDict from the typing module. This is a way to use Python dictionaries, but with type information about the values. It was introduced in Python 3.8, and extended though multiple releases.