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
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!
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.
In my case the api key was not enable. Make sure the API is set as Enabled.
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
.
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).
Just a note on the similar case I ran into with Swagger Editor:
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.