"internal server error" with API gateway and lambda on AWS

Viewed 2675

There are tons of similar questions both on this site and on the web, which leads me to believe there is something really wrong with AWS' documentation due to this causing grief to so many people.

So, I decided to post the most basic example step by step.

First, we create a new function:

enter image description here

It has default "everything", I don't touch a single line of code.

enter image description here

(the red error message is AWS not playing nice with Firefox)

The default code passes the test:

enter image description here

Now I add a trigger:

enter image description here

This gives me the link for the trigger:

enter image description here

I can go to the API endpoint: https://spy3z1jvu8.execute-api.ap-northeast-1.amazonaws.com/default/test

And it works:

enter image description here

Now, the problems will start. I open the API gateway that was created:

enter image description here

and try the default link: https://spy3z1jvu8.execute-api.ap-northeast-1.amazonaws.com

And...

enter image description here

Most of the people having similar questions seem to be having an issue with the gateway expecting some json content, etc, but here is an untouched AWS sample and the gateway link doesn't work.

The troubleshooting steps say to add logging and troubleshoot it that way, but there is nothing of interest in the logs.

What could be the origin of that problem?

1 Answers

What could be the origin of that problem?

You are correct. This is AWS/console fault. Specifically, it provides wrong permissions in the lambda's resource-based permissions for the default route to work. To fix that you have to edit the permissions.

Specifically, go to your function's Resource-based policy (this is different then execution role). You should find one Policy statement there which you have to edit. Then change in Source ARN from something like:

arn:aws:execute-api:ffffff:xxxx:api-id/*/*/function-name

to

arn:aws:execute-api:ffffff:xxxx:api-id/*/*
Related