Troubleshooting AWS API Gateway POST issues

Published on 31 March 2022


Having just created a POST API on the AWS API Gateway, I learnt a few things, and it have been good to know them before I started. These are all things that are probably obvious to someone who has experience with developing APIs, but not when you are early in the journey.

Use the TEST functionality in the API Gateway

Assuming you have created your lambda function and your API, then defined the method request, you will have the option to test it within the console. This is a vital step as if there are any errors in the code, you will see it here. Also, I have never seen a configuration so bad that this option cannot actually run your lambda function.

Hopefully you function has permission to write to CloudWatch logs, so when you run the Lambda function manually from the Lambda console, or via test, you should be able to see what happens. If not, that is a key step in any troubleshooting.

Once that works, you can test from the URL.

Testing the URL

When you get the URL from the stage, you can then try and test this. If you copy it into a browser, you will probably get back something like:

     {"message":"Missing Authentication Token"} 

This is a fairly generic error which can have several meanings. Assuming you are not trying to use authentication, this could be that the path you are using is wrong.

So if the URL is:

You need to add the path that you defined to the request.

Note that we don't have POST in here. Even if you try something like, it isn't going to work. What you need to do, is use either something like curl (curl -X POST), or Postman and create a POST request there, using the URL just above with the URL and path.

Once that has done, you should get a status code 200 back to show success, and you should actually see CloudWatch logs for your triggered Lambda function. If you are not seeing CloudWatch logs for your attempt to hit the API, but you do from executing the Lambda function from the Lambda console, you know that the function is not even being triggered so you still have an API Gateway issue (path probably).

Hope that helps someone having similar issues!

comments powered by Disqus