javascript - 无服务器(aws-node):从不同的文件调用函数返回内部服务器错误
问题描述
所以我有以下功能serverless.yml
functions:
getEstimate:
handler: handler.getEstimate
events:
- http:
path: /get-quotation
method: get
getQuotation:
handler: lalamove/index.getQuotation
events:
- http:
path: /lalamove-get-quote
method: get
我有这段代码,handler.js
它从 lalamove/index.getQuotation 调用 getQuotation() 函数。
'use strict';
var lalamove = require("./lalamove/index.js");
module.exports.getEstimate = (event, context, callback) => {
lalamove.getQuotation();
};
在无服务器部署之后,我看起来运行了我得到的 getEstimate 端点,{"message": "Internal server error"}
但是如果我尝试运行 getQuotation,{"message":"hermbs"}
当我运行 getEstimate 时,我也会得到应该打印的端点。
这是我的index.js
'use strict';
module.exports.getQuotation = (data, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: "hermbs",
}),
};
callback(null, response);
};
我在这里错过了什么吗?
解决方案
我不认为像这样调用另一个 lambda 函数是最佳实践。我建议在第三个“shared/util”模块中提取您需要的代码,并让两个模块从第三个模块导入他们需要的功能
推荐阅读
- python - 使用 IMAP、Python 向 Gmail 添加标签
- reactjs - React 不再抛出 lint 警告
- spring-boot - WebSocketStompClient stompSession 未来超时
- javascript - React Hooks useState 在一个 mouseOver 函数中更改多个元素状态只想更改鼠标悬停在一个
- java - 玩!框架功能测试幽灵数据
- reactjs - 反应钩子,更新一个状态以响应另一个状态更新
- java - 无法使用 Spring Boot 通过邮递员更新表格内容
- reactjs - ReactJS 通过父更改兄弟状态
- typescript - 子类型与其超类型的交集是否与子类型相同?
- r - 由 coercion 引入的 NAs 由 knn 中的 coercionError 引入