Add AWS CDK to an existing nx project
Zeke Sebulino
Posted on September 15, 2022
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
2. Run the cdk init command
npx cdk init app --language=typescript
3 Moved cdk.json
file from cdk folder to your project root. And replace app with custom js path.
{
"app": "dist/iac/main.js",
...
}
4 Install aws cdk package
npm i --save-dev aws-cdk
npm i aws-cdk-lib constructs
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
💖 💪 🙅 🚩
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.