7

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):
    (...)
Filipe Aleixo
  • 3,924
  • 3
  • 41
  • 74

3 Answers3

0

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

bwest
  • 9,182
  • 3
  • 28
  • 58
-1

Possible duplicate question -- Nodejs - Invoke an AWS.Lambda function from within another lambda function

Note, you may want to take a look at Step Functions to prevent Lambda A from incurring costs as it waits for Lambda B to complete.

Nick Walsh
  • 1,807
  • 5
  • 16
-1

On the second lambda, you just need to do id = context['id']. When it's an asynchronous call, event doesn't come with the body key.

Filipe Aleixo
  • 3,924
  • 3
  • 41
  • 74
  • It would benefit any readers if you clarified the differences between reading from event and reading from context, and in what situations they should be accessed. – Chris Ivan Mar 15 '21 at 03:29
  • I got this error message `"errorMessage": "'LambdaContext' object is not subscriptable"` if I used context to retrieve payload. – James Huang Jan 31 '23 at 12:06