Supported Languages
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- packages/aws-cdk/lib/init.ts
- packages/@aws-cdk/cfnspec/build-tools/create-missing-libraries.ts
- packages/decdk/README.md
- tools/pkglint/lib/rules.ts
- packages/@aws-cdk/aws-appflow/package.json
- packages/@aws-cdk/aws-codebuild/package.json
- packages/@aws-cdk/core/package.json
- design/construct-tree.md
The AWS Cloud Development Kit (AWS CDK) is a software development framework that allows developers to define cloud infrastructure using familiar programming languages. This polyglot capability is a cornerstone of the CDK, enabling teams to use their preferred language and tools to provision AWS resources. The CDK achieves this through a combination of project initialization templates, a core framework, and the jsii toolchain, which synthesizes object-oriented classes in supported languages from a single TypeScript source.
The primary supported languages are TypeScript/JavaScript, Python, Java, .NET, and Go. The CDK provides the cdk init command to bootstrap new projects with language-specific templates. Beyond imperative programming, the CDK ecosystem also includes deCDK, a tool for defining CDK applications declaratively using JSON or YAML, similar to CloudFormation.
Sources: README.md:12-18, packages/decdk/README.md:3-7, packages/aws-cdk/lib/init.ts:25-36
Official Language Support
The AWS CDK officially supports several popular programming languages, each with specific version requirements. This ensures that developers can leverage modern language features while maintaining compatibility with the CDK framework.
| Language | Version Requirement |
|---|---|
| JavaScript/TypeScript | Node.js ≥ 10.13.0 (excluding 13.0.0-13.6.0) |
| Python | Python ≥ 3.6 |
| Java | Java ≥ 8 and Maven ≥ 3.5.4 |
| .NET | .NET Core ≥ 3.1 |
| Go | Go ≥ 1.16.4 (Developer Preview) |
Sources: README.md:21-29
Project Initialization (cdk init)
The cdk init command is the entry point for creating a new CDK application. It uses a template-based system to generate the necessary project structure and boilerplate code for a chosen language.
Sources: packages/aws-cdk/lib/init.ts:25-36
Initialization Flow
The initialization process involves selecting a template and a language, which then generates project files from templates stored within the aws-cdk package.
The following diagram illustrates the cdk init workflow.
The InitTemplate Class
The InitTemplate class is responsible for managing and installing project templates. It discovers available templates and their supported languages from the packages/aws-cdk/lib/init-templates/ directory.
This diagram shows the structure of the InitTemplate class.
Sources: packages/aws-cdk/lib/init.ts:70-224
Template Variable Expansion
During the install process, the InitTemplate class uses the expand method to replace placeholder variables in template files with project-specific values. This allows for dynamic generation of file contents and names.
| Variable | Description | Example Value |
|---|---|---|
%name% | The decamelized name of the project directory. | my-cdk-project |
%name.camelCased% | The project name in camelCase. | myCdkProject |
%name.PascalCased% | The project name in PascalCase. | MyCdkProject |
%cdk-version% | The current version of the AWS CDK. | 1.120.0 |
%cdk-home% | The CDK home directory. | ~/.cdk |
%name.PythonModule% | The project name formatted as a Python module. | my_cdk_project |
%python-executable% | The Python executable for the OS (python3 or python). | python3 |
%name.StackName% | The project name sanitized for use as a CloudFormation Stack name. | my-cdk-project |
Sources: packages/aws-cdk/lib/init.ts:182-191
JSII and Polyglot Packages
The AWS CDK's multi-language support is powered by JSII. It allows code written in TypeScript to be published as libraries in other languages. Each CDK module's package.json file contains a jsii section that defines the compilation targets for each language.
This process is automated for new CloudFormation namespaces by the create-missing-libraries.ts script, which generates the necessary package.json configuration for Java, .NET, and Python.
The diagram below shows how a single TypeScript source is used by JSII to generate packages for multiple languages.
Java Target
Java packages are configured with a Maven Group ID and Artifact ID, and a Java package name.
Example package.json for @aws-cdk/aws-appflow:
{
"jsii": {
"targets": {
"java": {
"package": "software.amazon.awscdk.services.appflow",
"maven": {
"groupId": "software.amazon.awscdk",
"artifactId": "appflow"
}
}
}
}
}
Sources: packages/@aws-cdk/aws-appflow/package.json:14-21, tools/pkglint/lib/rules.ts:654-657
Python Target
Python packages are configured with a distribution name (distName) for PyPI and a module name for imports.
Example package.json for @aws-cdk/aws-codebuild:
{
"jsii": {
"targets": {
"python": {
"distName": "aws-cdk.aws-codebuild",
"module": "aws_cdk.aws_codebuild",
"classifiers": [
"Framework :: AWS CDK",
"Framework :: AWS CDK :: 1"
]
}
}
}
}
Sources: packages/@aws-cdk/aws-codebuild/package.json:20-29, tools/pkglint/lib/rules.ts:681-685
.NET Target
.NET packages are configured with a C# namespace and a NuGet package ID. They also include a URL for the package icon.
Example package.json for @aws-cdk/core:
{
"jsii": {
"targets": {
"dotnet": {
"namespace": "Amazon.CDK",
"packageId": "Amazon.CDK",
"iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png"
}
}
}
}
Sources: packages/@aws-cdk/core/package.json:14-20, tools/pkglint/lib/rules.ts:741-743
Go Target
Go support is in developer preview. The package.json files in the main repository indicate Go is a target language, as seen in the main README.md.
Sources: README.md:28-29
Declarative Language Support (deCDK)
In addition to imperative programming languages, the CDK ecosystem offers deCDK, a tool for declaratively defining CDK applications using JSON or YAML. This provides a CloudFormation-like experience but with the power to instantiate high-level CDK constructs.
deCDK processes a template, identifies resources with types like @aws-cdk/aws-sqs.Queue, and instantiates them as CDK constructs. Standard CloudFormation resources (e.g., AWS::SQS::Queue) are passed through directly.
Example hello.json for deCDK:
{
"$schema": "./cdk.schema.json",
"Resources": {
"MyQueue": {
"Type": "@aws-cdk/aws-sqs.Queue",
"Properties": {
"fifo": true
}
}
}
}
This can be synthesized using the CDK CLI: cdk -a "decdk hello.json" synth.
Sources: packages/decdk/README.md:3-28
Conclusion
The AWS CDK's support for multiple languages is a core feature that enhances developer productivity and flexibility. This is primarily achieved through the JSII toolchain, which transpiles TypeScript-based construct libraries into equivalent packages for Python, Java, .NET, and Go. The cdk init command further simplifies the developer experience by providing language-specific project templates. Finally, deCDK extends this flexibility by offering a declarative, CloudFormation-like syntax for defining infrastructure, making the CDK accessible to an even wider range of developers and workflows.
Sources: README.md:12-18, packages/aws-cdk/lib/init.ts, packages/decdk/README.md