AWS CDK Toolkit CLI

2.1118.4 · active · verified Wed Apr 22

The `aws-cdk` package provides the command-line interface (CLI) for the AWS Cloud Development Kit (CDK), a framework enabling developers to define cloud infrastructure using familiar programming languages (TypeScript, JavaScript, Python, Java, C#, Go) and provision it through AWS CloudFormation. As of version 2.1118.4, the CLI operates on CDK applications to synthesize CloudFormation templates, deploy, diff, and manage AWS resources. It maintains a rapid release cadence, often seeing multiple updates daily, with continuous bug fixes and feature enhancements across various underlying CDK modules. A key differentiator is its ability to abstract CloudFormation complexities, offering higher-level constructs and supporting advanced development workflows like `cdk watch` for rapid iteration and `cdk migrate` for importing existing resources. The CLI and the Construct Library (packaged as `aws-cdk-lib`) have independent release cadences since February 2025, though they remain compatible, with the CLI generally supporting Construct Library versions released before or with it.

Common errors

Warnings

Install

Imports

Quickstart

This TypeScript code defines a basic AWS CDK application with an S3 bucket and a Node.js Lambda function. The `aws-cdk` CLI would then be used to synthesize (`cdk synth`) and deploy (`cdk deploy`) this infrastructure to an AWS account after `cdk init` and `cdk bootstrap`.

import { App, Stack } from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';

const app = new App();

const myStack = new Stack(app, 'MySimpleCdkStack', {
  env: {
    account: process.env.CDK_DEFAULT_ACCOUNT,
    region: process.env.CDK_DEFAULT_REGION,
  },
});

new s3.Bucket(myStack, 'MyBucket', {
  versioned: true,
  // Ensure bucket name is unique
  bucketName: `my-unique-cdk-bucket-${myStack.account?.toLowerCase()}-${myStack.region?.toLowerCase()}`
});

new NodejsFunction(myStack, 'MyLambdaFunction', {
  runtime: lambda.Runtime.NODEJS_18_X,
  entry: 'src/handler.ts',
  handler: 'handler',
  environment: {
    MESSAGE: 'Hello from CDK Lambda!',
  },
});

// Dummy handler file for NodejsFunction (src/handler.ts)
// export async function handler(event: any) {
//   console.log('Received event:', JSON.stringify(event, null, 2));
//   return { statusCode: 200, body: process.env.MESSAGE || 'No message' };
// }

view raw JSON →