【问题标题】:aws lambda webpack generated fileaws lambda webpack 生成的文件
【发布时间】:2017-11-03 22:04:24
【问题描述】:

我正在尝试使用通过 webpack 生成的处理程序部署 aws lambda 函数。这是最终的 webpack 文件。为了便于理解,我删除了大部分标准 webpack 代码。

/******/ (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");


/***/ })

/******/ });

但是,当我尝试执行部署在 AWS 上的函数时,出现以下错误。文件名是storesHandler.js

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

【问题讨论】:

标签: amazon-web-services webpack aws-lambda


【解决方案1】:

我解决了这个问题。万一其他人遇到同样的问题,修复是在 webpack.config.js 文件中。在输出部分我不得不提到 commonjs 和 libraryTarget。

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

【讨论】:

  • 每次我都在努力寻找答案时,它就像一个字符或一行一样简单。这对我有用。谢谢!
猜你喜欢
  • 2019-11-20
  • 2018-03-08
  • 2019-09-22
  • 1970-01-01
  • 2018-06-02
  • 2021-11-24
  • 2018-01-28
  • 2021-07-08
  • 2020-12-04
相关资源
最近更新 更多