hupe1980 / cdkdx

Zero-config CLI for aws cdk development
MIT License
38 stars 8 forks source link

Deployed lambdas contain ts files rather than js #19

Closed krisb closed 2 years ago

krisb commented 3 years ago

I'm using the latest version of cdkdx (1.1.0) and cdk (1.123.0).

When I deploy a stack I see that the lambda is built in the output, e.g.

hello-world/index.js ⏤ 1.32 kB

But the asset folder under cdk.out only contains the index.ts file. Once deployed, the same files are visible in the code source on the lambda console and when testing I get the error message of "index.handler is undefined or not exported

I can find index.js locally under lib, and I was expecting this to be in the cdk.out asset folder and also uploaded.

Am I missing something obvious?

krisb commented 3 years ago

I used npx cdkdx create app <appName> as per the readme and also in the readme it mentions that cdk.json contains:

// cdk.json
{
  "app": "cdkdx node src/my-app.ts"
}

However, if I change this to:

// cdk.json
{
  "app": "cdkdx node lib/my-app.js"
}

things are working.

Is this the correct approach?

hupe1980 commented 3 years ago

The Code path must be correct at runtime and point to the folder with the index.js

new Function(this, 'Lambda1', {
  runtime: Runtime.NODEJS_12_X,
  handler: 'index.handler',
  code: Code.fromAsset(path.join(__dirname, 'lambdas', 'lambda1')), // Runtime => lib/lambdas/lambda1
});

You can use the following for a cdk app

...
code: Code.fromAsset(path.join(process.env.LAMBDAS as string, 'lambda1')), 
...

The correct cdk.json is:

{
  "app": "cdkdx node src/my-app.ts"
}