使用无服务器,我在 Node.js 中部署了一个带有多个 lambda 函数的 API 网关。我还使用 lambda 授权 (authenticate.js) 向一个 GET 端点添加了身份验证。我没有想法,所以任何帮助将不胜感激。我唯一能看到的是没有分配给授权人的 Lambda 调用角色。我没有找到任何关于如何将其添加到无服务器 yaml 的文档,但 Cloudwatch 日志没有显示任何授权方执行,所以我希望出现 403 或其他内容。
- 使用无服务器离线进行本地测试工作得很好
- 使用 Postman 在本地进行测试工作得很好
- 部署后,在 AWS 控制台中测试 lambda 就可以了
- 部署后,在 AWS 控制台中测试 API Gateway 方法就可以了
- 部署后,测试 authenticate.js Lambda 授权程序就可以了
- 部署后,在 Postman 中测试端点失败并返回以下错误:
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD>
<BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
We can't connect to the server for this app or website at this time. There might be too much traffic or a
configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: yx1B1i6k_J1nqf_jPMTN4AyHD8gKE85KajxhcosOMUZ-tHWoU1E54w==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY>
</HTML>
无服务器.yaml:
functions:
authenticate:
handler: src/handlers/auth.authenticate
list:
handler: src/handlers/api.list
events:
- http:
path: todos
method: get
cors: true
authorizer: authenticate
Lambda 授权人: