Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
cdktf
✓ npx cdktf init --template="typescript" --local
✗ import { cdktf } from 'cdktf-cli';
cdktf-cli is a command-line interface and is not designed for programmatic import into a Node.js application. Interact with it via shell commands using `npx cdktf` for ephemeral execution, or install globally with `npm install -g cdktf-cli` to use `cdktf` directly.
package.json script
✓ {
"scripts": {
"deploy": "cdktf deploy",
"synth": "cdktf synth"
}
}
For project-specific CLI usage, define scripts in your `package.json` to leverage the locally installed `cdktf-cli` binary from `node_modules/.bin` without requiring global installation.
This quickstart demonstrates how to initialize a new CDKTF project, define an AWS S3 bucket using TypeScript, and then deploy and destroy the infrastructure using the `cdktf` CLI commands.
// First, initialize a new CDKTF project (run these commands in your terminal):
// mkdir my-cdktf-project
// cd my-cdktf-project
// npx cdktf init --template="typescript" --local --project-name="my-s3-app" --stack-name="dev"
//
// When prompted, select 'typescript' as the language and choose an example like AWS S3 bucket.
//
// After initialization, modify the generated 'main.ts' file (e.g., in 'main.ts' or 'src/main.ts')
// to define an S3 bucket. You might need to install the AWS provider: 'npm i @cdktf/provider-aws'
import { Construct } from 'constructs';
import { App, TerraformStack, TerraformOutput } from 'cdktf';
import { AwsProvider } from '@cdktf/provider-aws/lib/provider';
import { S3Bucket } from '@cdktf/provider-aws/lib/s3-bucket';
class MyS3Stack extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id);
new AwsProvider(this, 'aws', {
region: 'us-east-1',
});
const bucket = new S3Bucket(this, 'my-unique-cdktf-bucket', {
bucket: `my-cdktf-example-bucket-${Math.random().toString(36).substring(2, 7)}`,
acl: 'private',
tags: {
Environment: 'Development',
ManagedBy: 'CDKTF',
},
});
new TerraformOutput(this, 'bucket_name', {
value: bucket.bucket,
description: 'The name of the S3 bucket created by CDKTF.',
});
}
}
const app = new App();
new MyS3Stack(app, 'my-s3-stack');
app.synth();
// To deploy this infrastructure, navigate to your project root in the terminal and run:
// npx cdktf deploy
//
// To destroy the deployed resources:
// npx cdktf destroy
cdktf --version
Errors
Common errors & fixes
Error: The installed Node.js version (v18.x.x) is not supported. Please upgrade to Node.js 20.9 or later.
Attempting to run `cdktf-cli` v0.21.0 or newer with an unsupported Node.js version (e.g., Node.js 18).
fixUpgrade Node.js to version 20.9 or higher. Use `nvm install 20 && nvm use 20` or install directly from nodejs.org.
Error: No stack found with ID 'my-s3-app'.
The `cdktf deploy` or `cdktf destroy` command was run with an incorrect stack ID, from the wrong directory, or before `cdktf synth` was executed successfully.
fixEnsure you are in the project root directory, verify the stack name matches the one defined in your code (e.g., `new MyS3Stack(app, 'my-s3-stack')`), and confirm that `cdktf synth` has been run to generate the Terraform configuration files.
Audit
Dependencies
No dependency data recorded yet.