Inwardly I groan every time I see a 403 come back from API Gateway.
Personally, I think they do it "wrong", but at the same time, I can see where they are coming from.
404 Issues
According to the HTTP standards, if a page doesn't exist, you should see a 404 response. This is what we all expect. When we see a 403, we start asking security-like questions, not "have I typed the right URL" questions.
In fact, the majority of times that I see a 403 with AWS API Gateway, the problem is that I have typed the wrong URL or am using the wrong method. To make matters worse, API Gateway gives you absolutely no logging to let you know that this is happening (at least, I haven't found any), possibly because it cannot think of anywhere to put that logging for a resource it cannot find.
The root cause of this appears to be that API Gateway can't tell if the non-existent resource would be secured if it did exist. Since it can't tell, it decides that it should tell you that you can't access it, rather than telling you that it doesn't exist.
Fixing the problem
So the first thing you need to do when encountering a 403 is to look very, very carefully at your URL and see if there is anything that could possibly be wrong with it. On the upside, if the hostname is wrong you do get a sensible error - but mainly because Route53 has not registered the domain name and so your browser cannot resolve it!
If you are still wondering what went wrong in the first post, it's that the stage/deployment name "Ignorance" is misspelled "ignorance" (yes, just a case error) in the URI that is assembled at the end of the createGateway.sh script. But it's a valuable point in two regards:
- URLs must contain the "stage name" in order to function (otherwise you'll get a 403)
- The stage name and resource name must both be spelled correctly (including case) or you will see a 403.
I am going to fix this from now on by having the stage name be lower case - but you will need to drop and recreate the gateway to see the changes.
Next: Let's Generate a Response
Next: Let's Generate a Response
No comments:
Post a Comment