无服务器脱机:"path"参数的类型必须是字符串。已接收未定义



不确定为什么会发生这种情况,但我有一个非常简单的无服务器应用程序,它正在运行,但现在当我运行sls offline start时,我收到了上面的错误。我已经找到了罪魁祸首,它是函数中的events

这是serverless.yml文件:

service: hello-world-offline
provider:
name: aws
runtime: nodejs12.x
region: eu-east-1
stage: dev
plugins:
- serverless-offline
functions:
hello-world:
handler: handler.handle # required, handler set in AWS Lambda
events:
- http:
path: hello-world
method: get
cors: true

这是handler.js文件:

module.exports.handle = async (event, ctx, cb) => {
cb(null, {
statusCode: 200,
body: JSON.stringify({ message: "hello world" })
})
}

如果我去掉函数hello-world中的events,那么sls offline start的一切都很好,当然,除了我实际上无法在本地到达端点这一事实之外。我试着通过添加引号使其成为一个硬字符串,但没有起到任何作用。

编辑:事实证明,使用yarn workspaces时会发生这种情况。如果我把它放在packages/my-serverless-app结构中,然后cd放在文件夹中运行sls offline start命令,就会发生这种情况。如果我把它从结构中移除,它就可以正常工作。

更改

events:
- http:
path: hello-world
method: get
cors: true

events:
- httpApi:
path: hello-world
method: get

这应该行得通!

相关内容

最新更新