Yoh*_*han 7 runtime amazon-web-services aws-lambda firebase-realtime-database
我是 AWS Lambdas 的新手 - 我正在尝试编写一个 lambda 函数来从 firebase 检索一些数据。我已调用此函数exports.handler 并将其与节点模块一起作为Zip 文件上传到Lambda。但是,当我尝试运行它时,它返回以下错误:
{
"errorType": "Runtime.HandlerNotFound",
"errorMessage": "index.handler is undefined or not exported",
"trace": [
"Runtime.HandlerNotFound: index.handler is undefined or not exported",
" at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)",
" at Object.<anonymous> (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:1156:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)",
" at Module.load (internal/modules/cjs/loader.js:1000:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:899
Run Code Online (Sandbox Code Playgroud)
这是我的功能:
module.exports.handler = async (event) =>{
ref.on("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
responses.push({
date: childSnapshot.val().Date,
name:childSnapshot.val().name,
response: childSnapshot.val().response
})
});
printObjects(responses);
console.log(json(responsesByPerson));
})
})
Run Code Online (Sandbox Code Playgroud)
我查看了与我类似的问题的其他答案,并实施了其中一些解决方案,但没有一个奏效。
当我们压缩一个目录时,shell 目录也会被添加到 zip 中,而 Lambda 期望它没有 shell 目录。使用以下命令正确创建 zip。
$ cd my_lambda_fun
$ zip -r lambda_one.zip .
Run Code Online (Sandbox Code Playgroud)
您必须确保压缩的不是您的项目,而是项目的内容。
例如,如果您index.js直接在内部my-project,您应该$> cd my-project然后使用内容创建一个 zip。然后可以将该 zip 上传到 AWS Lambda。
我希望这有帮助!
| 归档时间: |
|
| 查看次数: |
12030 次 |
| 最近记录: |