Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the return object in a Python-AWS lambda used?

In lambda function templates appear the return object

def lambda_handler(event, context):
   
    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "hello world 2",
        }),
    }

I couldn't find any documentation about how this object is used.

  • How must be configured?
  • What fields are mandatory?
  • When and how is it used? Can be consumed by other services?
like image 376
Aleix Avatar asked May 23 '26 16:05

Aleix


1 Answers

You do not need to return any value, but some calling systems want a response.

For example, if the Lambda function is invoked by API Gateway, it needs to send a response back to the original caller. See: Handle Lambda errors in API Gateway

It can also be used to pass back details errors: AWS Lambda function errors in Python

like image 60
John Rotenstein Avatar answered May 26 '26 08:05

John Rotenstein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!