Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda calling Lambda - how to access the payload in the second?

I'm calling a Lambda from another Lambda asynchronously using:

payload = {"id":item['id']}
invoke_lambda = lambda_client.invoke(FunctionName="process",
                                     InvocationType="Event",
                                     Payload=json.dumps(payload)) # Use InvocationType="RequestResponse" for synchronous run

This is likely rather obvious, but I can't find the documentation for it - how do I access the payload in the second lambda defined as:

def process(event, context):
    (...)
like image 923
Filipe Avatar asked Mar 29 '19 17:03

Filipe


People also ask

How do you invoke Lambda with payload?

To invoke a lambda function synchronously, use the invoke command, passing it the function name, the payload and the output filename as parameters. Copied! If you're on Windows , escape the double quotes of the --payload parameter, e.g. '{\"name\": \"John Smith\"}' .

How do you call a Lambda inside another Lambda?

In order to allow the ParentFunction to call the ChildFunction, we need to provide the ParentFunction with specific rights to call another lambda function. This can be done by adding specific policies to a role and then assign that role to the lambda function.

Can Lambda invoke another Lambda?

Async invocation means that the lambda that invokes the other lambda does not wait for the second lambda to finish and immediately returns. There are 2 lambdas. We will call them lambda-one and lambda-two. Lambda-one is invoked using APIGateway, and then lambda-one invokes the lambda-two asynchronously.


1 Answers

Your payload should be in the body of the event dict. Try json.loads(event['body']).get('id').

like image 127
bwest Avatar answered Sep 27 '22 01:09

bwest