My entry point is a .ts file -- here is the corresponding code in serverless.yml:
functions:
sheets:
handler: ./scripts/backend/handler.ts
When I deploy and invoke the lambda function on AWS, I get the error:
{
"errorMessage": "Bad handler ./scripts/backend/handler.ts"
}
It seems like the problem is that my webpack configuration converts the .ts files to .js files, so therefore when executing the lambda function it can't find the .ts file anymore. How do I fix this?
Here is my webpack config:
const slsw = require('serverless-webpack');
const webpack = require('webpack');
module.exports = {
entry: slsw.lib.entries,
target: 'node',
mode: slsw.lib.webpack.isLocal ? "development" : "production",
module: {
rules: [
{
test: [/\.tsx?$/],
exclude: [/node_modules/, /\.test.tsx?$/],
use:
[
{
'loader': 'ts-loader'
}
]
}
]
},
plugins: [
new webpack.DefinePlugin({
STAGE: `"${slsw.lib.options.stage}"`
})
],
resolve: {
modules: ['node_modules', 'scripts'],
extensions: ['.ts', '.tsx', '.json', '.js', '.jsx']
},
};
Found the problem -- I should have added the function name in the handler attribute, i.e. ./scripts/backend/handler.hello.
Most helpful comment
Found the problem -- I should have added the function name in the handler attribute, i.e.
./scripts/backend/handler.hello.