The Problem Link to heading

Recently I saw someone confused that they were unable to reach a Lambda via. API Gateway with a curl request. They received a Missing Authentication Token error, further complicating matters, because the API Gateway didn’t employ that sort of auth.

Some digging later, it turns out that API Gateway REST APIs deployed with Lambda give a strange error message when you hit the wrong route or method.

The weird API gateway lambda behavior Link to heading

If you set up httpAPI in serverless.yaml of a Serverless Framework API Gateway HTTP API as the trigger for a Lambda like this:

events:

- httpAPI:

path: /

method: get

You’ll get this result off a successful curl:

error-test-api % curl https://1jdp3vjz4d.execute-api.us-east-1.amazonaws.com/
{"message": "Go Serverless v4.0! Your function executed successfully!"

And this message on a wrong route:

error-test-api % curl https://1jdp3vjz4d.execute-api.us-east-1.amazonaws.com/foo
{"message":"Not Found"}

Here is the corresponding REST API behavior, with http as the event the Lambda triggers off of in Serverless:

events:

- http:

path: /

method: get

Correct CURL:

error-test-api % curl https://r28ziur6ul.execute-api.us-east-1.amazonaws.com/dev/

{"message": "Go Serverless v4.0! Your function executed successfully!"}

And here’s the ticket, an incorrect route or method:

error-test-api % curl https://r28ziur6ul.execute-api.us-east-1.amazonaws.com/dev/foo
{"message":"Missing Authentication Token"}

Solution/Conclusion Link to heading

Make sure to doublecheck what route you’re calling, and be suspicious of errors actually telling you what’s going on. Sometimes they can be misleading, as in this example.