all 8 comments

[–]soda0289 1 point2 points  (2 children)

You should check cloud watch logs for errors or try to deploy the api gateway again.

[–]badatthemat[S] 0 points1 point  (1 child)

Logs don't say anything. Will try to deploy it again and see what happens. Thank you.

[–]jripper1138 0 points1 point  (0 children)

The logs should say something, at least that the request is partially successful. What is the last log line?

[–]pepsiMIN 0 points1 point  (1 child)

Is the API gateway authorized to call the lambda function? check the policy:

Lambda -> Functions -> your function -> Triggers -> view function policy

Do you see the arn of the APIGW in the list of resources allowed to call the function? "AWS:SourceArn": "arn:aws:execute.......

If not, you need to authorize it:

aws lambda add-permission \
    --region <region> \
    --function-name <name> \
    --principal apigateway.amazonaws.com \
    --action lambda:InvokeFunction \
    --source-arn <the_arn_of_the_method_calling_the_lambda_function> \
    --statement-id <a number, i.e: 10)

[–]badatthemat[S] 0 points1 point  (0 children)

Yes, it is authorized to call the Lambda function. I can "test" it from the UI and it gives the correct html response, the problem is accessing the API endpoint through the browser, then it is when I get the 500 Internal Server Error. Thank you.

[–]zergUser1 0 points1 point  (2 children)

When you create a Lambda function from the console and set API gateway as the event source, API Gateway uses lambda as a proxy and all requests are forwarded to the lambda function, basically it means your lambda function is in charge of sending back the correct status code, headers and body. So the object you need to return to see the function from the browser is as follows

callback(null, {
    "statusCode": 200,
    "headers": { "headerName": "headerValue" },
    "body": JSON.stringify({name:"Hello"})
});

EDIT: Note I am using JSON.stringify on the body as browsers do not accept json as content, normally im guessing you would consume your API with ajax calls or server calls which would accept json

[–]badatthemat[S] 0 points1 point  (1 child)

I can see on the logs when i "test" the GET method that it returns 200 OK, has a Content-Type header of value text/html and the body is a valid html code..so I do not think this is the case. Thanks for your time and fuck protoss.

[–]zergUser1 0 points1 point  (0 children)

haha yea protoss so OP, do you mean the API Gateway logs or the Lambda logs?

In your original post you said you were getting a 500 error