I have a CDK app that is in typescript. I want fast development so I have been using cdk watch
. Whenever I make a change, the cdk stack is deployed. This works great, however, the app is not detecting my typescript lambda source code after deployment but it will detect the javascript file after I build the typescript. I was under the impression that I did not need to build my typescript files to deploy the cdk app.
Below is how I'm creating a lambda
const testLambda = new lambda.Function(this, 'TestLambda', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'api/example/get.handler',
code: lambda.Code.fromAsset('src/')
});
When I hit the API, I get the error Cannot find module get
, but if I run tsc
and then hit the api, it will find the get.js
file that is created.
Do I have to build my tsc files every time before deployment? If so, how can I detect a change in the typescript files, build them, and then deploy the cdk stack?
CodePudding user response:
Add the Typescript compile command to cdk.json
:
"build": "tsc",
cdk watch executes the "build" command from
cdk.json
to build your app before synthesis. If your deployment requires any commands to build or package your Lambda code (or anything else that's not in your CDK app proper), add it here.