python - 使用 SAM 在本地运行 Golang 函数时出现“找不到路由的 Lambda 函数”错误?
问题描述
我正在尝试按照此快速入门在 Golang 中编写一个 Lambda 函数(在运行 Docker Desktop 的 MacBook 上进行开发)。我执行以下步骤:
- 运行“sam init --runtime go1.x --name testing”以从模板生成一个函数。
- 跑“make deps”去获取依赖项。
- 运行“make build”来构建生成到 hello-world/hello-word 的代码。
- 跑“sam local start-api”。
一切看起来都正确启动:
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2019-11-16 10:39:19 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
但是当我 curl 端点时,我得到一个 502 并且我看到一个错误:
2019-11-16 10:39:23 Exception on /hello [HEAD]
Traceback (most recent call last):
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/flask/app.py", line 2317, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/flask/app.py", line 1840, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/flask/app.py", line 1743, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/flask/app.py", line 1838, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/flask/app.py", line 1824, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/samcli/local/apigw/local_apigw_service.py", line 172, in _request_handler
route = self._get_current_route(request)
File "/usr/local/Cellar/aws-sam-cli/0.31.0/libexec/lib/python3.7/site-packages/samcli/local/apigw/local_apigw_service.py", line 236, in _get_current_route
raise KeyError("Lambda function for the route not found")
KeyError: 'Lambda function for the route not found'
2019-11-16 10:39:23 127.0.0.1 - - [16/Nov/2019 10:39:23] "HEAD /hello HTTP/1.1" 502 -
我错过了什么?
解决方案
在这个聚会上迟到了,你可能已经解决了。没有看到任何代码,看起来您发出了 HEAD 请求,而不是 GET 请求,我怀疑您没有 HEAD 方法的路由,只有 GET。
推荐阅读
- c++ - 直接在类外调用构造函数会隐式创建一个对象吗?
- c++ - 哈希函数中对 c_str() 与 const char* 的函数调用
- powershell - Start-Process -WindowStyle Maximized 不会最大化窗口
- java - 在java中按升序对数组进行排序
- assembly - 更改地址在堆栈中的变量
- python - NoReverseMatch 在 /blog/2018/
- python - 如何将我的数据框中的两列添加到 np.array
- javascript - 如何使用 Javascript 将我的 Json 翻译成 HTML?
- html - 移动设备上的网页视图 - 只有上半部分正确显示?
- amazon-web-services - Webpack 4 + Jest + Babel 7 (+AWS Lambda):测试在本地通过,部署到 AWS Lambda 时出错