Aws-sam-cli: Unable to run sam local start-api in debug mode since upgrade to 0.2.7

Created on 27 Feb 2018  路  13Comments  路  Source: aws/aws-sam-cli

Starting up sam local for debugging with following command:
sam local start-api -p 3010 -d 5858

Also tried setting the SAM_LOCAL_DEBUG environment variable.
export SAM_LOCAL_DEBUG=5858

In both cases, when sending a request to an endpoint on the api on port 3010, i can see the lambda gets invoked, but an exception is thrown before going in debug mode.

2018/02/27 21:44:24 Invoking specs_get_all.handler (nodejs6.10)
2018/02/27 21:44:24 Mounting /Users/user/development/bitbucket/cda-validation-services/aggregate-service as /var/task:ro inside runtime container
2018/02/27 21:44:25 Function returned an invalid response (must include one of: body, headers or statusCode in the response object): unexpected end of JSON input

Most helpful comment

Fixed and created a new release 0.2.8

All 13 comments

Experiencing the same issue. Running sam local generate-event api | sam local invoke --debug-port 9229 ExampleFunction works with version 0.2.6, but not with 0.2.7. The resulting output is:

2018/02/27 21:52:08 Successfully parsed template.yaml
2018/02/27 21:52:08 Connected to Docker 1.35
2018/02/27 21:52:08 Fetching lambci/lambda:nodejs6.10 image for nodejs6.10 runtime...
nodejs6.10: Pulling from lambci/lambda
Digest: sha256:d2676f05ff1f812fa639b5bb6f89b579ff20574b2a01b9a11ac78824a558bca8
Status: Image is up to date for lambci/lambda:nodejs6.10
2018/02/27 21:52:11 Reading invoke payload from stdin (you can also pass it from file with --event)
2018/02/27 21:52:11 Invoking index.handler (nodejs6.10)
2018/02/27 21:52:16 WARNING: No AWS credentials found. Missing credentials may lead to slow startup times as detailed in https://github.com/awslabs/aws-sam-local/issues/134
2018/02/27 21:52:16 Mounting /Users/emillunde/projects/aws/lambda-workshop/del2 as /var/task:ro inside runtime container

The template file is provided below:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Lambda triggered by calls to API
Resources:
  ExampleFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs6.10
      Handler: index.handler
      Events:
        ExampleApi:
          Type: Api
          Properties:
            Path: /
            Method: any

I get the same result as @rnijholt . This definitely is new as of the SAM 0.2.7 release, as I was using debug mode on Friday.

Taking a look.. Is this specific to nodejs?

I have only tested in nodejs so far.

EDIT: The exact command my team has been using to debug in nodejs has been:

sam local start-api --template ./my-service.sam.yml --debug-port 5858 --parameter-values 'ParameterKey=paramReleaseVersion,ParameterValue=0.0.1'

I have only seen this issue debugging a nodejs lambda function

Same problem here, 0.2.7 is not able to debug nodejs lambda functions

I'm seeing a similar problem with a java8 runtime function, also since upgrading from 0.2.6 to 0.2.7.

sam local invoke -t lambda-stack.yaml -d 42000 --event event.json "TestResource" gives the usual output, but then fails with the line Error: Could not find or load main class Full output below (modified to remove project-specific names):

2018/03/01 14:21:08 Successfully parsed lambda-stack.yaml 2018/03/01 14:21:08 Connected to Docker 1.35 2018/03/01 14:21:08 Fetching lambci/lambda:java8 image for java8 runtime... java8: Pulling from lambci/lambda Digest: sha256:e1c82c7707c28f533480c76bb93a010f2279f699a0d7f8d3e9727082e0a81051 Status: Image is up to date for lambci/lambda:java8 2018/03/01 14:21:09 Invoking LambdaFunctionClass::handleRequest (java8) 2018/03/01 14:21:26 WARNING: No AWS credentials found. Missing credentials may lead to slow startup times as detailed in https://github.com/awslabs/aws-sam-local/issues/134 2018/03/01 14:21:26 Mounting code/location as /var/task:ro inside runtime container Error: Could not find or load main class

Fixed and created a new release 0.2.8

Thank you! I've confirmed that release 0.2.8 resolves the issue, as well as adds the new "chrome-devtools" debug feature!

Experiencing the same issue with Python on v 0.4.0

2018-07-04 18:38:37 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received: b'\n{"body": "[]", "statusCode": 200, "headers": {"Cache-Control": "max-age=1200"}'

@makskant Your problem is not related to this issue. Looks like there is a \n at the beginning of JSON response. This should be handled by the SAM CLI, but as a work around can you omit the trailing \n before you send response?

@sanathkr I have seen the newline symbol and wondering how it possibly could be there. I am testing on the simplest function, which returns an empty array in the body

def handler(event, context):
    return {'body':json.dumps([]), 'statusCode':200, 'headers': get_headers(event)}

@makskant Can you cut a new issue so we can start tracking this separately? Do mention the version of Python, version of SAM CLI, platform etc so we can debug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

red8888 picture red8888  路  3Comments

cmccoypdx picture cmccoypdx  路  3Comments

Caian picture Caian  路  3Comments

GerbenRampaart picture GerbenRampaart  路  3Comments

drumadrian picture drumadrian  路  3Comments