DEV Community

Zeke Sebulino
Zeke Sebulino

Posted on • Updated on

Add AWS CDK to an existing nx project

Credit to this post.

Pre-requisites

  • nx project
  • nx @nrwl/workspace library

1. In the root of your project, reate a new folder to place your cdk files.

md cdk
Enter fullscreen mode Exit fullscreen mode

2. Run the cdk init command

npx cdk init app --language=typescript
Enter fullscreen mode Exit fullscreen mode

3 Moved cdk.json file from cdk folder to your project root. And replace app with custom js path.

{
  "app": "dist/iac/main.js",
  ...
}
Enter fullscreen mode Exit fullscreen mode

4 Install aws cdk package

npm i --save-dev aws-cdk
npm i aws-cdk-lib constructs
Enter fullscreen mode Exit fullscreen mode

5 Copy the content of the file cdk/bin/cdk.ts into iac/src/main.ts. Copy the file cdk/lib/cdk-stack.ts to iac/src/app.stac.ts and update the import in main.ts to correctly point to it.

6 Build your nx library

7 run cdk bootstrap (if its the first time you're using cdk)

8 run cdk deploy --profile=zeke --app=dist/libs/iac/src/main.js

Top comments (0)