Simple guide to migrate Typescript Projects from AWS CDK v1 to v2

Balu Vyamajala
2 min readDec 4, 2021

--

CDK V2 is now GA, This is a simple guide to migrate typescript projects from v1 to v2.

Upgrade cdk globally

npm update -g aws-cdk

Changes to dependencies in package.json

Upgrade to typescript version 3.8 or later.

“typescript”: “3.9.0”

Remove all dependencies which start with @aws-cdk , all we need is just one aws-cdk-lib

“aws-cdk-lib”: “2.0.0”

Construct class is moved out to its own package. we need a new dependency

“constructs”: “10.0.0”

Simplified package.json will look like this.

Changes to import statements

All imports from @aws-cdk must be changed to aws-cdk-lib

V1: import * as s3 from ‘@aws-cdk/aws-s3’

V2: import * as s3 from ‘aws-cdk-lib/aws-s3’

core types are now at top level

V1: import * as cdk from ‘@aws-cdk/core’

V2: import * as cdk from ‘aws-cdk-lib’;

Construct is moved to constructs package.

V1: cdk.Construct

V2: import { Construct } from ‘constructs’; and use Construct(without cdk.)

Bunch of feature flags in cdk.json are enabled by default and are no more needed. we can remove all those which starts with @aws-cdk/

and Finally,

  • Delete node_modules and clean install npm install
  • redo bootstrap , if new way is not already done at account level. cdk bootstrap
  • check the differences cdk diff and deploy cdk deploy

References:

--

--