Skip to content

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

Closed

Description

@makskant

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 -

Activity

  1. jfuss commented on Jul 5, 2018

    @jfuss
    Contributor

    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!

  2. zsc347 commented on Jul 6, 2018

    @zsc347
    Contributor

    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'))
    
  3. sanathkr commented on Jul 6, 2018

    @sanathkr

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

  4. added
    contributors/good-first-issue
    on Jul 6, 2018
  5. jfuss commented on Jul 6, 2018

    @jfuss
    Contributor

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

  6. jfuss commented on Jul 17, 2018

    @jfuss
    Contributor

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

    Closing as this is released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/local/start-apicontributors/good-first-issuepriority/1-criticaltype/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions