javascript - Lambda 本地和 HTTP 调用
问题描述
我在node.js中有一个函数,需要在AWS中作为lambda托管。但是在我们托管它之前,我们需要检查该功能是否正常工作。我一直在尝试使用lambda-local运行该函数。但挑战是,我的逻辑中有外部 HTTP 调用。我为此使用Axios,但我得到的响应为undefined。有什么方法可以访问那些外部 HTTP 端点并获得响应?下面是命令行日志。提前致谢。
D:\Billing_&_Consumption\P2D-Phase2 - Billings\POC\scripts\controller>lambda-local -l DocumentsHandler.js -h getDocumentsList -e event.js
warning Using both auth systems: aws_access_key/id and secret_access_token !
info: START RequestId: 155ee184-1a7b-464a-eeac-d5593bde5abe
Response: undefined
TypeError: Cannot read property 'access_token' of undefined
at Object.DocumentsController.getDocumentsList (D:\Billing_&_Consumption\P2D-Phase2 - Billings\POC\scripts\controller\DocumentsController.js:26:87)
at Object._executeSync (C:\Users\429732\AppData\Roaming\npm\node_modules\lambda-local\lib\lambdalocal.js:169:47)
at Object._execute [as execute] (C:\Users\429732\AppData\Roaming\npm\node_modules\lambda-local\lib\lambdalocal.js:40:22)
at C:\Users\429732\AppData\Roaming\npm\node_modules\lambda-local\bin\lambda-local:133:21
at Object.<anonymous> (C:\Users\429732\AppData\Roaming\npm\node_modules\lambda-local\bin\lambda-local:169:3)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
error: End - Error
error: ------
error: {
"errorMessage": "Cannot read property 'access_token' of undefined",
"errorType": "TypeError",
"stackTrace": [
"Object.DocumentsController.getDocumentsList (D:\\Billing_&_Consumption\\P2D-Phase2 - Billings\\POC\\scripts\\controller\\DocumentsController.js:26:87)",
"Object._executeSync (C:\\Users\\429732\\AppData\\Roaming\\npm\\node_modules\\lambda-local\\lib\\lambdalocal.js:169:47)",
"Object._execute [as execute] (C:\\Users\\429732\\AppData\\Roaming\\npm\\node_modules\\lambda-local\\lib\\lambdalocal.js:40:22)",
"C:\\Users\\429732\\AppData\\Roaming\\npm\\node_modules\\lambda-local\\bin\\lambda-local:133:21",
"Object.<anonymous> (C:\\Users\\429732\\AppData\\Roaming\\npm\\node_modules\\lambda-local\\bin\\lambda-local:169:3)",
"Module._compile (module.js:652:30)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)"
]
}
error: ------
error: Lambda failed in 135ms.
我可以为您提供 axios 调用及其解决和拒绝
public getAccessToken(): AxiosPromise<any> {
return axios({
method: 'post',
url: `${URL}`,
data: this.data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
}
服务.ts
this.documentStoreBroker.getAccessToken()
.then((token: any) => {
console.log(token);
return new ADSAccessToken(token);
})
.catch(error => {
console.log(error);
throw new InternalServerError('99x100');
});
}
解决方案
推荐阅读
- c - 如何在 makefile 中包含项目目录之外的标头
- google-cloud-platform - 我将 Java 代码放在 Google Cloud Tasks 的什么位置
- javascript - 未使用 JavaScript 建立 WebSocket 连接
- reactjs - 找不到模块:无法解决“react-bootstrap”问题
- angularjs - 在Typescript中以json格式访问对象中的对象
- java - 如何获得 ConstraintViolation
- javascript - Reactjs 类与 javascript 类
- java - 将 spring boot 从 2.0.0 升级到 2.1.1 后未加载 application-test.properties
- php - c3条形图Y轴值固定值
- c# - TabControl 样式与 Binding 与 Direct Children 看起来不同