Add AWS CDK to an existing nx project

zekesebulino

Zeke Sebulino

Posted on September 15, 2022

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

💖 💪 🙅 🚩
zekesebulino
Zeke Sebulino

Posted on September 15, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024