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

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

Closed
seaders opened this issue Jan 14, 2019 · 1 comment

Comments

@seaders
Copy link

seaders commented Jan 14, 2019

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!

@jfuss
Copy link
Contributor

jfuss commented Apr 23, 2019

This was addressed in #1013

Closing as the PR was merged and released.

@jfuss jfuss closed this as completed Apr 23, 2019
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