aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Local API Gateway responds with Internal Server error

Open kaarthikeyansp opened this issue 9 years ago • 14 comments

Hi,

I have tried to execute the sample code from https://github.com/awslabs/aws-sam-local/tree/master/samples/api-event-source

But facing { "message": "Internal server error" } error when I access http://127.0.0.1:3000/

I'm executing in Window 10, so I used --docker-volume-basedir parameter

C:\Users\AWS-SAM-Local\samples\api-event-source>sam local start-api --docker-volume-basedir \c\Users\AWS-SAM-Local\samples\api-event-source

2017/11/07 16:14:33 Fetching lambci/lambda:nodejs6.10 image for nodejs6.10 runtime... nodejs6.10: Pulling from lambci/lambda Digest: sha256:7eb4ced6a15ae3c30effc4ec0cd3aabb2bd57c9a8330b37920c3d5d722d81083 Status: Image is up to date for lambci/lambda:nodejs6.10

Mounting index.handler (nodejs6.10) at http://127.0.0.1:3000/ [OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT] Mounting static files from \c\Users\AWS-SAM-Local\samples\api-event-source\public at /

2017/11/07 16:14:47 Invoking index.handler (nodejs6.10) Lambda starts successfully START RequestId: 52d4ca03-a557-1cb1-8695-91e22537a7b2 Version: $LATEST 2017-11-07T10:44:49.656Z 52d4ca03-a557-1cb1-8695-91e22537a7b2 test ---> log message from Lambda prints successfully END RequestId: 52d4ca03-a557-1cb1-8695-91e22537a7b2 REPORT RequestId: 52d4ca03-a557-1cb1-8695-91e22537a7b2 Duration: 5.91 ms Billed Duration: 0 ms Memory Size: 0 MB Max Memory Used: 28 MB Lambda ends successfully

2017/11/07 16:14:53 Function index.handler timed out after 3 seconds 2017/11/07 16:14:53 Error invoking nodejs6.10 runtime: io: read/write on closed pipe

Problem happens in last 2 lines (I presume), even I tried increasing timeout to 10 seconds, but didn't help

Please let me know what went wrong in this.

Regards, Kaarthikeyan

kaarthikeyansp avatar Nov 07 '17 10:11 kaarthikeyansp

I get the same error. Have you found a solution?

sejsworld avatar Nov 09 '17 21:11 sejsworld

@sejsworld Didn't get any solution yet. Let me know if case you resolved it.

kaarthikeyansp avatar Nov 10 '17 05:11 kaarthikeyansp

Your timeout looks 3s, try to increase in your template.

Resources:
  Products:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      Timeout: 10
      ...

diegotry avatar Nov 11 '17 08:11 diegotry

I tried increasing that to 20, but didn't solved the issue

aureshsaxena avatar Dec 04 '17 19:12 aureshsaxena

edit products.js file,

change

let id = event.pathParameters.product || false;

to

let id = event.pathParameters || false;

leifulstrup avatar Jan 17 '18 15:01 leifulstrup

@leifulstrup your suggestion corrects the bug in products.js but still there is no response from SAM.

PierrePrimot avatar Feb 28 '18 16:02 PierrePrimot

The container seem to ignore the function's Timeout setting and only has a timeout of 3s

vlamic avatar Mar 29 '18 10:03 vlamic

Just to clarify. The latest version of sam local respects the Timeout setting in the template. It then uses the value to set an environment variable AWS_LAMBDA_FUNCTION_TIMEOUT of the lambci/lambda container. Most likely that if you keep getting the 3s timeout despite of the Timeout setting in your template - either your sam local or the lambci/lambda image is outdated.

shpoont avatar Apr 05 '18 21:04 shpoont

Apparently it doesn't respect the Timeout setting in the Globals section. Works fine when specified for each function separately. Verified just now with the latest sam local from master + latest lambci/lambda images.

vlamic avatar Apr 05 '18 21:04 vlamic

I have sam version 0.2.10 and docker 18.03.0-ce-mac60 (23751) I get the same problem of timeout. I have increased the timeout to 10 secs and sam respects that value and I get timedout after 10secs The problem seems to be somewhere else. Any pointers?

kavuri avatar Apr 09 '18 02:04 kavuri

@kavuri have you tried running it in debug mode to find out if the lambda function works properly

femioladeji avatar Apr 11 '18 14:04 femioladeji

@andela-foladeji Figured out the problem. The reason was because my dynamodb-local was not running in a docker container and sam runs in docker. So I had to run dynamodb-local in docker and add it to the same network as sam The timeout error does not help to resolve the problem and had to really debug the whole code to get to the root

kavuri avatar Apr 12 '18 09:04 kavuri

This problems happens due to misconfigured SAM template or Lambda function app. I am going to close the issue because this is not a SAM CLI issue

sanathkr avatar May 31 '18 23:05 sanathkr

@andela-foladeji Figured out the problem. The reason was because my dynamodb-local was not running in a docker container and sam runs in docker. So I had to run dynamodb-local in docker and add it to the same network as sam The timeout error does not help to resolve the problem and had to really debug the whole code to get to the root

i try to run dynamodb-local inside docker by using

docker run -d -p 8000:8000 amazon/dynamodb-local

getting error when I try:

aws dynamodb list-tables --endpoint-url http://localhost:8000

Could not connect to the endpoint URL: "http://localhost:8000/"

debojit777 avatar Apr 26 '20 20:04 debojit777