Aws-sam-cli: Local API Gateway responds with Internal Server error

Created on 7 Nov 2017  路  14Comments  路  Source: aws/aws-sam-cli

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

Most helpful comment

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
      ...

All 14 comments

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

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

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
      ...

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

edit products.js file,

_change_

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

_to_

let id = event.pathParameters || false;

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

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

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.

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.

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 have you tried running it in debug mode to find out if the lambda function works properly

@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

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

@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/"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

burck1 picture burck1  路  45Comments

ericallam picture ericallam  路  24Comments

dinvlad picture dinvlad  路  27Comments

enghwa picture enghwa  路  25Comments

oldnerd picture oldnerd  路  25Comments