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

Answer from John Rotenstein on Stack Overflow
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › define lambda function handler in python
Define Lambda function handler in Python - AWS Lambda
January 31, 2026 - The context object is a Python class that's defined in the Lambda runtime interface client · . To return the value of any of the context object properties, use the corresponding method on the context object. For example, the following code snippet assigns the value of the aws_request_id property ...
Discussions

return value of python AWS Lambda.
Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey. ... I am trying to read dynamodb table and return values in python of Lambda. My return function is below More on repost.aws
🌐 repost.aws
3
0
November 1, 2022
return value from lambda function
I want to send response back to the caller of the lambda function, but since describe alarm function of cloudwatch is asynchronous, I am getting empty response in the body. How can I wait for the function to execute before returning the response? ... Is it perhaps an option to add an obserable for alarmStatus? If the value ... More on stackoverflow.com
🌐 stackoverflow.com
July 3, 2019
Returning a result from a lambda function
Use the doc https://docs.aws.amazon.com/lambda/latest/dg/API_InvokeAsync.html It says: Important For asynchronous function invocation, use Invoke. You seem to have mistaken the Node async call with the lambda async behaviour. These are two different things More on reddit.com
🌐 r/aws
1
1
July 30, 2019
amazon web services - how to get return response from AWS Lambda function - Stack Overflow
I have a simple lambda function that returns a dict response and another lambda function invokes that function and prints the response. lambda function A def handler(event,context): params = ... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 3
2
Decimal object is not JSON serializable. Use a package that can do that for you [1] or consider casting the Decimal into a float using a helper function [2]. 1. Use `simplejson` instead of `json` as it will do the decimal conversion for you. This would mean you need to use a Lambda layer to import that pip package. `import simplejson as json` 2. Use a custom class to do the conversion meaning you can avoid the Lambda layer: ``` from decimal import Decimal class DecimalEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, Decimal): return str(obj) return json.JSONEncoder.default(self, obj) ``` ``` json.dumps(item, cls=DecimalEncoder) ```
2 of 3
0
My code is def lambda_handler(event, context): dynamodb = boto3.resource("dynamodb") table = dynamodb.Table("OrderList") items = table.scan()['Items'] return { 'statusCode': 200, 'body': json.dumps(items[1]) } Response is { "statusCode": 200, "body": "{"TotalPrice": "101", "PartName": "Test Part", "ClientID": "user001", "UnitPrice": "50", "OrderDate": "28-10-2022", "PartID": "P003", "Status": "Sent", "Quantity": "1", "OrderID": "O0001"}" } ################################### return { 'statusCode': 200, 'body': json.dumps(items[1]) } Response is { "errorMessage": "Object of type Decimal is not JSON serializable", "errorType": "TypeError", "requestId": "5849b770-4dc6-4858-82ed-65fbecab1f6a", "stackTrace": [ " File "/var/task/lambda_function.py", line 76, in lambda_handler\n 'body': json.dumps(items)\n", " File "/var/lang/lib/python3.9/json/init.py", line 231, in dumps\n return _default_encoder.encode(obj)\n", " File "/var/lang/lib/python3.9/json/encoder.py", line 199, in encode\n chunks = self.iterencode(o, _one_shot=True)\n", " File "/var/lang/lib/python3.9/json/encoder.py", line 257, in iterencode\n return _iterencode(o, 0)\n", " File "/var/lang/lib/python3.9/json/encoder.py", line 179, in default\n raise TypeError(f'Object of type {o.class.name} '\n" ] }
🌐
Stack Overflow
stackoverflow.com › questions › 55044274 › return-value-from-lambda-function
return value from lambda function
July 3, 2019 - Copyconst AWS = require('aws-sdk'); exports.handler = (event) => { AWS.config.update({region: 'eu-west-1'}); var cw = new AWS.CloudWatch({apiVersion: '2010-08-01'}); var alarmStatus = {}; cw.describeAlarms({}, function(err, data) { if (err) { console.log("Error", err); } else { data.MetricAlarms.forEach(function (item, index, array) { var pair = {[item.AlarmName]: item.StateValue}; alarmStatus = {...alarmStatus, ...pair}; console.log(alarmStatus); }); } }); const response = { statusCode: 200, body: JSON.stringify(alarmStatus), }; return response; };
🌐
Reddit
reddit.com › r/aws › returning a result from a lambda function
r/aws on Reddit: Returning a result from a lambda function
July 30, 2019 -

I'm working on a c# application and using AWS lambda functions in the backend. The lambda function is working correctly and i'm able to call it from the application. The part I'm having trouble with is getting the code to wait for the result from the lambda function to be returned before continuing. I've looked into using the async/await pattern but i'm getting compile errors because AmazonLambda.InvokeAsync returns null.

This is the code what is correctly invoking the function and prints out the response but I'd like to instead return the response to the calling method. I've also tried changing the return from void to string and adding a return to the callback function but I get this error: "Anonymous function converted to a void returning delegate cannot return a value"

Any help is appreciated.

public void Invoke()

{

InvokeRequest invokeRequest = new InvokeRequest()

{

FunctionName = FunctionName,

Payload = Payload

};

Client.InvokeAsync(invokeRequest, responseObject =>

{

if (responseObject.Exception == null)

{

Debug.Log("LAMBDA SUCCESS: " + Encoding.ASCII.GetString(responseObject.Response.Payload.ToArray()));

}

else

{

Debug.Log("LAMBDA ERR: " + responseObject.Exception);

}

});

}

🌐
GitHub
github.com › aws › aws-sdk-java-v2 › issues › 3222
The return value of the lambda function is not expected · Issue #3222 · aws/aws-sdk-java-v2
May 31, 2022 - Describe the bug I have a simple lambda function like this exports.handler = async (event) => { return "string result"; }; when I invoke it via Java sdk the return value is: (double quotes around) "string result" Expected Behavior string...
Published   May 31, 2022
Author   x-wk
Find elsewhere
🌐
Reddit
reddit.com › r/awslambda › best practices on return / exit codes?
r/awslambda on Reddit: Best Practices on Return / Exit Codes?
January 3, 2021 -

Good Evening,
I'm relatively new to writing AWS Lambdas, and I've been writing some in Python lately.

My lambdas are generally structured where the handler function instantiating another class which calls a method to actually do the logic of the Lambda, which seems typical. Once this logic is done, it returns to the handler function and then exits. For perspective, these are lambdas that are invoked by an S3 event, do some file processing, insert data into a DB, and then exit.

I'm wondering if there are guidelines/tips/best practices on what the handler function should return, depending on whether there was a success or not. Additionally, having actual return code/exit codes would make testing easier, I imagine. I've seen some people use like HTTP Status codes returned as a dictionary, but I'm not sure if there's any benefit to that.

TLDR: Is there a standard or best practice for return/exit codes from AWS Lambdas - Success or Failures?

🌐
AWS
aws.amazon.com › blogs › compute › running-code-after-returning-a-response-from-an-aws-lambda-function
Running code after returning a response from an AWS Lambda function | Amazon Web Services
May 7, 2024 - Before the synchronous function returns, it invokes the second function asynchronously, either directly, using the Invoke API, or indirectly, for example, by sending a message to Amazon SQS to trigger the second function. This Python code demonstrates how to implement this: import json import time import os import boto3 from aws_lambda_powertools import Logger logger = Logger() client = boto3.client('lambda') def calc_response(event): logger.info(f"[Function] Calculating response") time.sleep(1) # Simulate sync work return { "message": "hello from async" } def submit_async_task(response): # In
🌐
Trek10
trek10.com › homepage › blog listing › aws lambda functions: return response and continue executing
AWS Lambda Functions: Return Response and Continue ...
While it’s not documented you can in fact return a response and continue executing in certain circumstances. In this post, I’ll explain how to do this using the Node.js Lambda runtime. But first, I’d like to explain how Lambda streaming responses work. According to the documentation, to enable streaming responses you have to turn on function urls and enable the streaming response. In your code, you have to wrap your handler function with a wrapper provided by the AWS Lambda Node.js runtime.
Price   $
Address   1400 E. Angela Blvd, Suite 209, 46617, South Bend
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › define lambda function handler in node.js
Define Lambda function handler in Node.js - AWS Lambda
Completing tasks during initialization typically improves cold-start performance, and first invoke performance when using Provisioned Concurrency. For more information, see our blog post Using Node.js ES modules and top-level await in AWS Lambda ... When you configure a function, the value of the Handler setting is the file name and the name of the exported handler method, separated by a dot.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › using the lambda context object to retrieve python function information
Using the Lambda context object to retrieve Python function information - AWS Lambda
get_remaining_time_in_millis – Returns the number of milliseconds left before the execution times out. function_name – The name of the Lambda function. ... invoked_function_arn – The Amazon Resource Name (ARN) that's used to invoke the function. Indicates if the invoker specified a version number or alias. memory_limit_in_mb – The amount of memory that's allocated for the function. aws_request_id – The identifier of the invocation request.
🌐
Medium
medium.com › @sgpropguide › useful-tips-for-writing-aws-lambda-functions-in-python-e7d16ea44cfa
Tips for writing AWS lambda functions in python | by sgpropguide | Medium
May 9, 2019 - Our lambda function can return an interactive webpage built on top of Vue that can make API calls and display results. In the example below, the app gets users to fill up test cases and their solutions — before posting the test cases and solutions ...
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with java › define lambda function handler in java
Define Lambda function handler in Java - AWS Lambda
Setting up your Java handler ... the AWS SDK for Java v2 in your handlerAccessing environment variablesUsing global stateCode best practices for Java Lambda functions · The Lambda function handler is the method in your function code that processes events. When your function is invoked, Lambda runs the handler method. Your function runs until the handler returns a response, ...
🌐
Readthedocs
aws-lambda-for-python-developers.readthedocs.io › en › latest › 02_event_and_context
Chapter 2: What is the event & context? - AWS Lambda for Python Developers
However when invoked synchronously (e.g. via API), the return value will be returned to the calling application, and usually must be returned in a specific structure. For example, AWS Lambda console uses the synchronous invocation type, so when you invoke the function using the console, the console will display the returned value (serialized into json)
🌐
AWS
docs.aws.amazon.com › aws sdk for .net › developer guide › sdk for .net code examples › lambda examples using sdk for .net
Lambda examples using SDK for .NET - AWS SDK for .NET (V3)
Find the complete example and learn how to set up and run in the AWS Code Examples Repository ... /// <summary> /// Invoke a Lambda function. /// </summary> /// <param name="functionName">The name of the Lambda function to /// invoke.</param /// <param name="parameters">The parameter values that will be passed to the function.</param> /// <returns>A System Threading Task.</returns> public async Task<string> InvokeFunctionAsync( string functionName, string parameters) { var payload = parameters; var request = new InvokeRequest { FunctionName = functionName, Payload = payload, }; var response = await _lambdaService.InvokeAsync(request); MemoryStream stream = response.Payload; string returnValue = System.Text.Encoding.UTF8.GetString(stream.ToArray()); return returnValue; }
🌐
Stack Overflow
stackoverflow.com › questions › 77800216 › aws-lambda-getting-a-return-value-from-lambda-and-using-in-cloud-formation-temp
amazon web services - AWS Lambda: Getting a return value from lambda and using in Cloud Formation template - Stack Overflow
I have a Lambda that checks if network configurations are present in an AWS account. I have invoked this lambda as part of an stack execution (this is an Cloud formation template). Now the Lambda invoked will return a Dictionary as a response/return value.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with c# › define lambda function handler in c#
Define Lambda function handler in C# - AWS Lambda
You implement this method to serialize the result returned from your Lambda function handler into the response payload that the Invoke API operation returns. The main example on this page uses reflection-based serialization. Reflection-based serialization works out of the box with AWS Lambda ...