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

Getting an invalid response with new line symbol at the response on SAM CLI 0.4.0 #531

Closed
makskant opened this issue Jul 5, 2018 · 5 comments
Labels
area/local/start-api sam local start-api command contributors/good-first-issue Good first issue for a contributor priority/1-critical type/bug

Comments

@makskant
Copy link

makskant commented Jul 5, 2018

Description:

Steps to reproduce the issue:

  1. Function handler
def handler(event, context):
    return {'body': json.dumps([]), 'statusCode': 200, 'headers': {"Cache-Control":"max-age=1200"}}
  1. Resource
    TestFunction:
        Type: AWS::Serverless::Function
        Properties:
            Handler: test.handler
            Role: !GetAtt FunctionRole.Arn
            CodeUri: functions/
            AutoPublishAlias: live
            Events:
                Api:
                    Type: Api
                    Properties:
                        Path: /test
                        Method: get

  1. Running sam local start-api and trying to requests a http://127.0.0.1:3000/test

Observed result:

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"}}'

Expected result:
Expecting to have an empty array as a response with status code 200

OS: Ubuntu 16.04

Output of sam --version: 0.4.0

Python version: 3.6.1.

Optional Debug logs:

START RequestId: 90197d0b-c013-4575-bbe0-2eb8c3d67714 Version: $LATEST
END RequestId: 90197d0b-c013-4575-bbe0-2eb8c3d67714
REPORT RequestId: 90197d0b-c013-4575-bbe0-2eb8c3d67714 Duration: 339 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 29 MB
2018-07-05 16:52:11 http://localhost:None "GET /v1.35/containers/db47404069e7220f7ee521898dad6f27131a5e8f8b6d2b0a6d035aa3ffd9097e/json HTTP/1.1" 200 None
2018-07-05 16:52:11 http://localhost:None "DELETE /v1.35/containers/db47404069e7220f7ee521898dad6f27131a5e8f8b6d2b0a6d035aa3ffd9097e?force=True&v=False&link=False HTTP/1.1" 204 0
2018-07-05 16:52:11 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"}}'
2018-07-05 16:52:11 127.0.0.1 - - [05/Jul/2018 16:52:11] "GET /test HTTP/1.1" 502 -
2018-07-05 16:52:11 127.0.0.1 - - [05/Jul/2018 16:52:11] "GET /favicon.ico HTTP/1.1" 403 -

@jfuss
Copy link
Contributor

jfuss commented Jul 5, 2018

hmmm... Something is going wrong in this function but at first glance I can't reason about what the actually issue is. I will need to run the cli with pdb with your template and code.

Note: Thank you for providing the code and template. This makes tracking this down much easier!

@zsc347
Copy link
Contributor

zsc347 commented Jul 6, 2018

I've found a fix.
This line should be

if last_line_position >= 0:

And there is another error which will cause decode exception.
This line shoud be

json_output = json.loads(lambda_output.decode('utf-8'))

@sanathkr
Copy link
Contributor

sanathkr commented Jul 6, 2018

@zsc347 Can you send a PR to fix the >=0 bug along with a unit tests? Should be super easy.

For the second one, @jfuss is working on this code path in #532. I have made a note of this comment there. He should be able to handle it.

@sanathkr sanathkr added the contributors/good-first-issue Good first issue for a contributor label Jul 6, 2018
@jfuss
Copy link
Contributor

jfuss commented Jul 6, 2018

Acknowledging I will handle the second one @zsc347 provided in my current PR @sanathkr linked.

@jfuss
Copy link
Contributor

jfuss commented Jul 17, 2018

Both bugs called out here were addressed with released v0.5.0

Closing as this is released

@jfuss jfuss closed this as completed Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/start-api sam local start-api command contributors/good-first-issue Good first issue for a contributor priority/1-critical type/bug
Projects
None yet
Development

No branches or pull requests

4 participants