【发布时间】:2019-03-12 21:18:49
【问题描述】:
我有一个刚刚初始化的无服务器项目:
severless.yml:
service: lambda
provider:
name: aws
runtime: nodejs8.10
region: us-east-1
functions:
hello:
handler: handler.hello
events:
- http:
path: /hello
method: GET
plugins:
- serverless-offline
我用sls offline --port 8080运行它:
Serverless: Starting Offline: dev/us-east-1
Serverless: Routes for hello:
Serverless: GET /hello
Serverless: Offline listening on http://localhost:8080
在我的handler.ts
module.exports.hello = async (event, context) => {
console.log('HIIII')
return {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
};
我在本地在 Postman 上点击了这个端点,但它似乎不起作用。我得到的只是一些 HTML,上面写着Cannot GET /hello。我尝试向http://localhost:8080/dev/hello 或http://localhost:8080/hello 发出GET 请求,但我仍然遇到同样的错误。我在这里做错了吗?
【问题讨论】:
-
你确定吗?我只是复制/粘贴了您示例的每个部分,
http://localhost:8080/hello工作得很好。 -
@Spacebear5000 你提到了 handler.ts,你确定你在 serverless.yml 上引用了正确的 js 文件吗?
-
可能与您的回调有关。检查它是否正在返回某些内容,并且根据您用于发出请求的工具,它可能无法识别响应。
-
您很可能需要重新启动“无服务器离线”命令。
标签: serverless-framework serverless