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 = event['list'] return {"params" : params + ["abc"]}
lambda function B invoking A
a=[1,2,3] x = {"list" : a} invoke_response = lambda_client.invoke(FunctionName="monitor-workspaces-status", InvocationType='Event', Payload=json.dumps(x)) print (invoke_response)
invoke_response
{u'Payload': <botocore.response.StreamingBody object at 0x7f47c58a1e90>, 'ResponseMetadata': {'HTTPStatusCode': 202, 'RequestId': '9a6a6820-0841-11e6-ba22-ad11a929daea'}, u'StatusCode': 202}
Why is the response status 202? Also, how can I get the response data from invoke_response? I could not find a clear documentation of how to do it.
The lambda functions do not need a return statement, they always return a single expression.
Returning a valueIf you use the RequestResponse invocation type, such as Synchronous invocation, AWS Lambda returns the result of the Python function call to the client invoking the Lambda function (in the HTTP response to the invocation request, serialized into JSON).
If you use the RequestResponse invocation type, such as Synchronous invocation, AWS Lambda returns the result of the Python function call to the client invoking the Lambda function (in the HTTP response to the invocation request, serialized into JSON).
Start the lambda function. Download data from a dummy API to local file system. Copy the downloaded files to AWS S3. Stop the lambda function. The lambda function will be scheduled to run every 5 minutes. Let’s assume you work for a company that wants to pull some data from an API that you have access to and assess the quality of that data.
The Lambda Placeholder. Create a simple Lambda function that returns an HTML string. Log into to the AWS Console and navigate to the Lambda service. Create a new Lambda function and select the hello-world template. Name the function lambda-html. Input the code block below to return some basic html.
Lambda functions run inside an AWS Firecracker container. When you return from your Lambda function, AWS immediately freezes the container and its global state. When the Lambda is next invoked, it will thaw the container to service the new invocation.
A 202
response means Accepted
. It is a successful response but is telling you that the action you have requested has been initiated but has not yet completed. The reason you are getting a 202
is because you invoked the Lambda function asynchronously. Your InvocationType
parameter is set to Event
. If you want to make a synchronous call, change this to RequestResponse
.
Once you do that, you can get the returned data like this:
data = invoke_response['Payload'].read()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With