2 Answers
- Newest
- Most votes
- Most comments
1
Hi there! I've seen others tackle this problem with tooling like Learn (https://lerna.js.org/). However, I would be wary of going the monorepo direction as the CDK team has baked in a lot of tooling around packaging and deploying JS/TS lambda's. If you were to go this route you would be reinventing the wheel, I could only recommend it if the problem is prevalent and not just a hammer in search of a nail.
answered 3 years ago
1
Hi. It is possible to organize your lambda business code separately while still using NodejsFunction package. The folder structure could be like this:
/cdk └── cdk-stack.ts /lambda └── src └── handlers └── index.ts └── package.json └── tsconfig.json
Then you need to point to your package-lock file and business code path
new lambdaNode.NodejsFunction(stack, 'example-service-lambda', { entry: path.resolve(__dirname, '../lambda/src/handlers/index.ts'), // path to your Lambda handler handler: 'handler', // the handler function depsLockFilePath: path.resolve(__dirname, '../lambda/package-lock.json'), // package-lock file projectRoot: path.resolve(__dirname, '../lambda'), // set project root to the Lambda folder bundling: { tsconfig: path.resolve(__dirname, '../lambda/tsconfig.json'), // tsconfig file for TypeScript support }, });
This question motivated me to write an article about organizing project structure. See link for more details
answered a year ago
Relevant content
- asked a year ago
