部署到AWS时未调用无服务器Lambda授权程序

时间:2020-02-10 00:25:00

标签: aws-lambda aws-api-gateway serverless-framework lambda-authorizer

使用无服务器,我在Node.js中部署了具有若干lambda函数的API网关。我还使用lambda authorizo​​r(authenticate.js)将身份验证添加到一个GET端点。我没有主意,因此不胜感激。我唯一看到的是没有分配给授权者的Lambda调用角色。我没有找到有关如何将其添加到无服务器yaml中的任何文档,但是Cloudwatch日志未显示任何授权者执行,因此我期望403或类似的内容。

  1. 使用无服务器脱机进行本地测试就可以了
  2. 使用Postman进行本地测试就可以了
  3. 部署后,在AWS控制台中测试lambda即可正常运行
  4. 部署后,在AWS控制台中测试API Gateway方法就可以了
  5. 部署后,测试authenticate.js Lambda授权器就可以了
  6. 部署后,在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>

serverless.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授权者:

enter image description here

enter image description here

0 个答案:

没有答案
相关问题