The main point of the cdk.json file is to specify the entry point for your application. As referenced in the provided article, it mentions the following about cdk.json:
cdk.json instructs the toolkit on how to execute your application. In our scenario, it will be "npx ts-node bin/cdk-workshop.ts"
Clarifications:
Now, once I transfer my code from the /bin directory to the /lib directory, how can I recreate the bin/cdk-workshop.ts file?
Simply put, cdk init
is essentially a tool that assists developers in setting up the initial project structure. This generation process occurs only once. There's no need to regenerate the file; you can simply make edits to it. The reason for its significance as the starting point is because it initializes an instance of App
and generates instances of Stacks
. Furthermore, you have the flexibility to name this file as per your preference.
For instance, instead of the conventional setup, you could create a new folder named entrypoint
parallel to both bin
and lib
. Within this folder, establish a new file titled startup.ts
Here's a sample snippet for startup.ts
:
import * as cdk from '@aws-cdk/core';
import { MyCoolStack} from '../lib/my-cool-stack';
import { MyLameStack} from '../lib/my-lame-stack';
const app = new cdk.App();
new MyCoolStack(app, 'MyCoolStack', {});
new MyLameStack(app, 'MyLameStack', {});
Subsequently, there are two approaches to define this file as the entry point.
Inline
cdk synth --app "npx ts node entrypoint/startup.ts"
Alternatively through cdk.json:
{
"app":"npx ts node entrypoint/startup.ts"
}
Note: While my background primarily involves working with C# for cdk applications rather than TypeScript, these insights are based on my understanding of how it functions within a C# context.