aws lambda webpack generated file

六月ゝ 毕业季﹏ 提交于 2019-12-11 01:58:16

问题


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:


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'
}


来源:https://stackoverflow.com/questions/47047110/aws-lambda-webpack-generated-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!