Moto: Lambda response not correctly returned to invoker

Created on 10 Dec 2019  路  2Comments  路  Source: spulec/moto

How to reproduce

In file my_module.py:

def my_lambda(event, context):
    return '"ok"'  # a JSON string 

Create the lambda function using boto3:

>>> create_function(FunctionName='my_lambda', Handler='my_module.my_lambda', Role='some-role', Code={'ZipFile': my_zip}, Publish=True, Runtime='python3.6')

then invoke it:

>>> invoke(FunctionName='my_lambda', InvocationType='RequestResponse')['Payload'].read()
b'\x1b[32mSTART RequestId: 0417092f-ea57-1db3-0083-35882dc25044 Version: $LATEST\x1b[0m\n\x1b[32mEND RequestId: 0417092f-ea57-1db3-0083-35882dc25044\x1b[0m\n\x1b[32mREPORT RequestId: 0417092f-ea57-1db3-0083-35882dc25044\tInit Duration: 217.97 ms\tDuration: 3.77 ms\tBilled Duration: 100 ms\tMemory Size: 128 MB\tMax Memory Used: 26 MB\t\x1b[0m\n\n"ok"}'

As you see, I get the "ok" string returned by my lambda besides a bunch of logging info.

What I expected to happen

I expected "ok" alone to be returned.
Besides, I expected the return status to be 200, but it is always 202.

What version of moto

1.3.14

Thanks.

bug

Most helpful comment

Hi @clapas, @clowtown - the response issue should be fixed, now that #2669 is merged in.
I'll close this one, as the HTTPStatusCode is already captured in a different issue

All 2 comments

We may need to open an issue explicitly on the return code - given the AWS docs stating RequestRespnose should return a 200: https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_ResponseSyntax

Where the test is explicitly checking a 202:
https://github.com/spulec/moto/blob/8e2e3cec5a5b31ad4b81c24e087b4df6f1a2b279/tests/test_awslambda/test_lambda.py#L117

Hi @clapas, @clowtown - the response issue should be fixed, now that #2669 is merged in.
I'll close this one, as the HTTPStatusCode is already captured in a different issue

Was this page helpful?
0 / 5 - 0 ratings