Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sam local start-api: Function returned an invalid response... Response received has '\n' #540

Closed
josephthweatt opened this issue Jul 6, 2018 · 3 comments

Comments

@josephthweatt
Copy link

Description:

I am trying to call the lambda function using a request to the start-api, the function is executing, but when it tries to return I get this error:

Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received: b'\n{ "statusCode": 200, "jsonvalues": "values" }'

This is the same issue mentioned by @makskant a couple days ago on #314
It was recommended by @sanathkr to cut a new issue to discuss this. As Sanath noted, the issue is likely that \n is getting returned with the json. However, the handler looks something like this:

def my_handler(event, context):
    
    # function code

    return { "statusCode": ###, "jsonvalues": "values" }  # return back JSON

I do not see any newline character before the object, so I am wondering if I am doing something wrong here. What could be causing this issue?

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Linux OS, function written using Python 3.6

Output of sam --version:
0.4.0

@jfuss
Copy link
Contributor

jfuss commented Jul 6, 2018

Duplicate of #531

To answer the "I am wondering if I am doing something wrong here. What could be causing this issue?":
The new line character is added due to the response of the Lambda Docker is given as the last line in the stdout from the container. Since we parse the stdout to get the return, we need to strip out all newlines (and other characters). This is where the '\n' character is coming from.

@jfuss jfuss closed this as completed Jul 6, 2018
@josephthweatt
Copy link
Author

@jfuss I see. So this is a bug then. Will there be a fix to this fairly soon?

@jfuss
Copy link
Contributor

jfuss commented Jul 6, 2018

@josephthweatt I am working on prioritizing it in an upcoming sprint but can't say when we will have a fix or a release that addresses this. You can follow the issue I linked to stay updated with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants