getting message: forbidden reply from AWS API gateway

前端 未结 20 1068
鱼传尺愫
鱼传尺愫 2020-11-30 04:34

I am trying to create a lambda service on AWS and have it accessed from outside via the API gateway with no authentication or restriction required.

To make things ea

相关标签:
20条回答
  • 2020-11-30 04:50

    This may be far from obvious, but another reason of seeing "Forbidden" error when using AWS API Gateway may be calling incorrect URL that does not correspond to any deployed API method. It can occur if you're actually hitting wrong URL (e.g. instead of calling https://9999xx9x99.execute-api.us-east-1.amazonaws.com/dev/users (note dev stage before users) you called https://9999xx9x99.execute-api.us-east-1.amazonaws.com/users (no stage). You'd expect to get 404, but you'll get 403.

    BTW: after you make a deployement to https://9999xx9x99.execute-api.us-east-1.amazonaws.com/dev/users calling https://9999xx9x99.execute-api.us-east-1.amazonaws.com/user (note singular noun form here) you'll get… 403 as well, but with "Missing Authentication Token" message!

    0 讨论(0)
  • 2020-11-30 04:53

    Local Firewall / antivirus or NGIPS (Cisco Bluecoat). The latter was my case, where I wouldn't even get logs in CloudWatch from my API. It was allowing my top level domain hosted website, but was blocking with 403 the api subdomain, with no body in the browser's network dev-tools tab.

    0 讨论(0)
  • 2020-11-30 04:58

    In my case the api key was not enable. Make sure the API is set as Enabled.

    0 讨论(0)
  • 2020-11-30 04:59

    If you use a custom domain name and forget to select destination staging, you'll get the Forbidden message.

    Simply go to Custom Domain Names and click Edit under your domain, and then select the stage under Base Path Mappings.

    0 讨论(0)
  • 2020-11-30 04:59

    We had faced this issue in our production when we used Kong as our api gateway. Our requests passed thro when initiated from Postman but failed with 403 when initiated via Code. The Bot plugin in Kong was enabled which only allowed requests initiated from Browser or Mobile App based on the user agent header value.Our requests initiated via Http Client failed. Once we disabled the bot plugin then the error didnt occur. It now allows request if the user-agent is Apache-HttpClient/4.5.2 (Java/1.8.0_91).

    0 讨论(0)
  • 2020-11-30 05:01

    Just a note on the similar case I ran into with Swagger Editor:

    • I exported the OpenAPI 3.0 YAML from API Gateway → Stages → select "Prod" → select "Export" tab → switch radiobutton to "OpenAPI 3" → "Export as OpenAPI 3 + API Gateway Extensions"
    • Paste the received YAML to https://editor.swagger.io/
    • Execute a trivial GET method.
    • It returns 403 Forbidden with {"message":"Forbidden"} body.

    curl command from Swagger Editor looked like this:

    curl -X GET "https://xxx52xxxx9.execute-api.eu-central-1.amazonaws.com//Prod/users" -H "accept: application/json"

    (note the double // before Prod).

    And the same curl command without // worked via the command line!

    The trick that worked is to replace this server structure returned in the API Gateway-generated:

    servers:
      - url: "https://xxx52xxxx9.execute-api.eu-central-1.amazonaws.com/{basePath}"
        variables:
          basePath:
            default: "/Prod"
    

    With the full url without variables:

    servers:
      - url: "https://xxx52xxxx9.execute-api.eu-central-1.amazonaws.com/Prod"
    

    Notably, removing the leading slash from default: "/Prod" didn't help.

    0 讨论(0)
提交回复
热议问题