Skip to content

Blueprint code from microservice-http-endpoint-python3 fails due to string statusCode #937

@seaders

Description

@seaders

I'm sure this has been reported already because of the other Function returned an invalid response (must include one of: body, headers or statusCode in the response object) reason, but the real reason is showing up for me on the previous line,

statusCode must be a positive int

When you then check the code supplied by the blueprint, in the respond function, you'll see,

def respond(err, res=None):
    return {
        'statusCode': '400' if err else '200',
        'body': err.message if err else json.dumps(res),
        'headers': {
            'Content-Type': 'application/json',
        },
    }

https://github.com/awslabs/serverless-application-model/blob/master/examples/apps/microservice-http-endpoint-python3/lambda_function.py#L13

If you change that function to,

def respond(err, res=None):
    return {
        'statusCode': 400 if err else 200,
        'body': err.message if err else json.dumps(res),
        'headers': {
            'Content-Type': 'application/json',
        },
    }

The problem is resolved and your function works as it's supposed to. Now, whether that's your bad or... the other awslabs' (the history says it's @sanathkr 's code) bad, I don't know! Because I'm using this, I decided to log the bug here. It might be a case where you guys maybe should try json.load statusCode, if it's a str and that code should also be returning ints instead, again I don't know!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions