DEV Community

Zeke Sebulino
Zeke Sebulino

Posted on • Edited on

4 1

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay