2
votes

I'm trying to deploy a aws lambda function with the handler generated through webpack. This is the final webpack file. I have removed most of the standard webpack code for ease of understanding.

/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};
/******/
/******/    // The require function
/******/    function __webpack_require__(moduleId) {


/******/ }
/************************************************************************/
/******/ ({

/***/ "./storesHandler.js":
/***/ (function(module, exports, __webpack_require__) {

"use strict";


module.exports.get = function (event, context, callback) {
  var response = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Go Serverless v1.0! Your function executed successfully!',
      input: event
    })
  };

  callback(null, response);

  // Use this code if you don't use the http event with the LAMBDA-PROXY integration
  // callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};

/***/ }),

/***/ 0:
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__("./storesHandler.js");


/***/ })

/******/ });

However when I try to execute the function that gets deployed on AWS I get the following error. The name of the file is storesHandler.js

{
  "errorMessage": "Handler 'get' missing on module 'storesHandler'"
}
1

1 Answers

3
votes

I solved the problem. Just in case someone else comes across the same issue, the fix was in the webpack.config.js file. In the output section I had to mention commonjs ans the libraryTarget.

output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '../build'),
    filename: 'storesHandler.js'
}