AWS禁止使用403

时间:2020-03-29 09:59:24

标签: amazon-web-services aws-api-gateway serverless-framework aws-serverless

我已经完成了https://serverless-stack.com上的Notes App教程(唯一的变化是我正在连接到MongoDB)。 Notes应用程序是使用“资源”中的基础结构yml创建的。 一切正常。

然后,我决定更改serverless.yml并重新添加提供的“ hello” api(包括将handler.js添加到项目中)。 该API仅返回一条消息。 完成之后,我执行了$serverless deploy —stage dev Notes应用程序继续工作。

在Amazon API Gateway中执行“ hello” API可以得到200。 当我使用npx aws-api-gateway-cli-test运行—path-template=‘/hello’时,系统会给我一个“ 403禁止”。 当我用npx aws-api-gateway-cli-test运行--path-template=‘/notes’时,可以给我200,好。

我不明白为什么禁止拨打“ hello”电话403?

放在旁边:之所以重新添加提供的“ hello” API是因为我还设置了一个具有相同问题的新项目(与Notes应用程序相同) -我无法调用任何此类新项目API(我已写过这些API),因为它们都给出了“ 403 forbidden”。

这是serverless.yml中定义的“ hello” API:

  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get
          authorizer: aws_iam

我已确认:

npx aws-api-gateway-cli-test--path-template=’/hello’调用。

npx aws-api-gateway-cli-test默认为GET。

--invoke-url=‘https://“ID”.execute-api.us-east-2.amazonaws.com/dev’看起来也不错。

在serverless.yml中使用GET方法将路径定义为“ hello”。

该处理程序称为handler.js,并包含一个名为hello的函数(由本教程提供)。

检入API Gateway > Stages > dev的调用URL为https://“ID”.execute-api.us-east-2.amazonaws.com/dev/hello。 (在两种情况下,“ ID”都替换为正确的匹配ID,但不带引号)

与本教程唯一的不同之处在于,由于我未连接到Dynamo,因此在serverless.yml中没有定义任何iamRoleStatements。

当我完全不熟悉此方法时,任何帮助都将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:0)

您基本上回答了您的问题

我没有任何iamRoleStatements

您需要确保为lambda服务和API网关提供了适当的IAM角色。它们没有预先配置。