'Exporting dependency from node_modules to aws lambda
I have a problem with exported function to AWS Lambda written with using Typescript and NodeJS. After triggering this function I get this error:
"Error: Cannot find module 'express'
My function is a simply worker handling by cron, to running every day. Here is my serverless.yml:
service: some-name
plugins:
- serverless-webpack
provider:
name: aws
region: eu-central-1
runtime: nodejs14.x
stage: dev
functions:
someFunction:
handler: dist/services/users.dailyWorker
events:
- schedule:
rate: cron(0 0 * * ? *)
enabled: true
and here is also my webpack.config:
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: 'ts-loader' },
],
},
externals: [nodeExternals()]
};
I found that my function didn't see any of the packages from node_modules. Can someone tell me how to import also needed dependency to AWS Lambda?
Thanks for any help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
