Use the AWS CDK (Cloud Development Kit) with LocalStack



The AWS Cloud Development Kit (CDK) is an IaC (Infrastructure-as-Code) tool using general-purpose programming languages such as TypeScript/JavaScript, Python, Java, and .NET to programmatically define your cloud architecture on AWS.

AWS CDK CLI for LocalStack

cdklocal is a thin wrapper script for using the AWS CDK library against local APIs provided by LocalStack.


The cdklocal command line is published as an npm library:

# Install globally
npm install -g aws-cdk-local aws-cdk

# Verify it installed correctly
cdklocal --version
# e.g. 1.65.5


cdklocal can be used as a drop-in replacement of where you would otherwise use cdk when targeting the AWS Cloud.

$ cdklocal --help


The following environment variables can be configured:

  • EDGE_PORT: Port under which LocalStack edge service is accessible (default: 4566)
  • LOCALSTACK_HOSTNAME: Target host under which LocalStack edge service is accessible (default: localhost)
  • LAMBDA_MOUNT_CODE: Whether to use local Lambda code mounting (via setting __local__ S3 bucket name)


Make sure that LocalStack is installed and successfully started with the required services before running the example

$ curl http://localhost:4566/_localstack/health

The CDK command line ships with a sample app generator to run a quick test for getting started.

# create sample app
mkdir /tmp/test; cd /tmp/test
cdklocal init sample-app --language=javascript

# deploy the sample app 
cdklocal deploy
> Do you wish to deploy these changes (y/n)? y

Once the deployment is done, you can inspect the created resources via the awslocal command line

$ awslocal sns list-topics
     "Topics": [
             "TopicArn": "arn:aws:sns:us-east-1:000000000000:TestStack-TestTopic339EC197-79F43WWCCS4Z"

Other resources

External resources

Community resources

Last modified December 1, 2022: LocalStack Beta Docs (#337) (28576f89)