I am trying to use Weback to build a simple lambda nodejs function hello world.
exports.handler = (event, context, callback) => {
callback(null, 'Hello from Lambda');
};
This function works in lambda with handler "index.handler" configured in aws lambda configuration page.
Webpack generated code for the above does not work. The function throws the error "Handler 'handler' missing on module 'index'". It looks like module becomes antonyms.
It can be made to work by updating the generated code as below.
global.handler = (event, context, callback) => {
//async.map(['file1','file2','file3'], console.log, function(err, results){
// results is now an array of stats for each file
callback(null, 'Hello from Lambda');
//});
//add the following at the end.
exports.handler = global.handler;
webpack.config.js as follows.
var path = require('path');
module.exports = {
// Specify the entry point for our app.
entry: [
path.join(__dirname, '/src/autotag.js')
],
// Specify the output file containing our bundled code
output: {
path: path.join(__dirname, "dist"),
filename: "autotag.js"
},
//target: "node",
module: {
/**
* Tell webpack how to load 'json' files.
* When webpack encounters a 'require()' statement
* where a 'json' file is being imported, it will use
* the json-loader.
*/
loaders: [{
test: /\.json$/,
loaders:
}]
}
}
Anyone using webpack to build lambda nodejs functions?
Any help appreciated.