AWS Lambda Webpack生成的文件 [英] aws lambda webpack generated file
问题描述
我正在尝试通过通过webpack生成的处理程序部署aws lambda函数.这是最终的webpack文件.为了方便理解,我删除了大多数标准的webpack代码.
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");
/***/ })
/******/ });
但是,当我尝试执行在AWS上部署的功能时,出现以下错误.该文件的名称为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'"
}
推荐答案
我解决了这个问题.以防万一其他人遇到相同的问题,此修复程序在webpack.config.js文件中.在输出部分中,我不得不提到commonjs和libraryTarget.
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'
}
这篇关于AWS Lambda Webpack生成的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!