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): (...) 

4 Answers 4

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

Neither of the suggested solutions worked for me in 2024, but

id = event['id'] 

did.

Comments

-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.

2 Comments

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.
I got this error message "errorMessage": "'LambdaContext' object is not subscriptable" if I used context to retrieve payload.
-2

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.

1 Comment

Thanks for the suggestion, but I'm doing it in Python - not nodejs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.