Sravanthi Gudidevini
Sravanthi Gudidevini

Reputation: 19

Pass object instance through lambda invoke function in python

I have multiple Lambda functions. I am calling another Lambda function from the first Lambda function using Lambda invoke in python. I have an object instance of the class which has has the dictionary data. I also want to pass the object instance to the other lambda functions with the json object. How can I do it?

objReferenceData = ReferenceData()
objReferenceData_dict = objReferenceData.__dict__
"This objReferenceData_dict contains all the data which have dictonary object." 

## First lambda
inputForInvoker = responsejson
logger.info(inputForInvoker)
response = client.invoke(
            FunctionName = 'arn:aws:firstfun',
            InvocationType = 'RequestResponse',
            Payload = json.dumps(inputForInvoker)
                )
responsejson = json.load(response['Payload'])
return responsejson
            else:
                pass
            
## second lambda
inputForInvoker = responsejson
response = client.invoke(
            FunctionName = 'arn:aws:secondfun',
            InvocationType = 'RequestResponse',
            Payload = json.dumps(inputForInvoker)
                )
responsejson = json.load(response['Payload'])
else:
    pass

I want to pass the objReferenceData_dict with the responsejson. I tried to send that, adding this objReferenceData_dict to the responsejson but the data is too large. The lambda handler only has a limit of 6mb.

Upvotes: 0

Views: 1066

Answers (1)

theherk
theherk

Reputation: 7566

You seem to understand the api for invoking another lambda synchronously, so it seems your only issue is the 6MB limit. This is a hard limit according to the documentation.

Therefore, you must choose another method for data transfer. There are, of course, many options. Two that come to mind are writing the data as an object to s3 with put_object, or sending the message to an sqs queue since you can Now Send Payloads up to 2GB with Amazon SQS.

For the former, you would invoke the second lambda with the key of the s3 object. For the latter, you would trigger the second lambda via the queue, and then handle the response with a different workflow.

In any case, if you need to invoke with more that 6MB, you cannot pass the payload directly.

Upvotes: 1

Related Questions