Reputation: 411
I have a child lambda function which I can invoke successfully from the parent and get a 200 status code but the parent lambda gets an empty string despite the fact the the child lambda is returning the expected data. I am fairly new to python, so I am sure it is something simple that I'm missing.
Child Lambda
# empty data dict as this can change in the function due to various conditions
data{}
# populate data dict for returned payload
data["first_string"] = 'first'
data["second_string"] = 'second'
data["first_number"] = 100
# this is what the child lambda returns and what expect to get when I invoke from the parent lambda
return json.dumps(data)
Child lambda output is as expected. See below.
"{\"first_string\": \"first\", \"second_string\": \"second\", \"first_number\": 100}"
Parent lambda
response = Lambda_client.invoke(
FunctionName='lambda-function-arn',
InvocationType='RequestResponse',
Payload=json.dumps(input_params),
LogType='Tail'
)
response_payload = response['Payload'].read().decode("utf-8")
print("This is the response from the child lambda" + response_payload)
Parent lambda response_payload is an empty string. When I print it (as above) I get...
This is the response from the child lambda"{}"
It should contain the output from the child lambda. Can anyone tell me what I'm doing wrong?
Upvotes: 0
Views: 1482
Reputation: 1161
Everything in your code is working correctly. I have created two Python 3.9 lambda functions. And the parent lambda is getting the correct response.
Things to try:
parent lambda
import json
import boto3
Lambda_client = boto3.client('lambda')
def lambda_handler(event, context):
inputParams = {}
response = Lambda_client.invoke(
FunctionName='arn',
InvocationType='RequestResponse',
Payload=json.dumps(inputParams),
LogType='Tail'
)
print(response)
response_payload = response['Payload'].read().decode("utf-8")
print("This is the response from the child lambda" + response_payload)
return {
'statusCode': 200,
'body': json.dumps('This is the parent lambda')
}
child lambda
import json
def lambda_handler(event, context):
data = {}
data["first_string"] = 'first'
data["second_string"] = 'second'
data["first_number"] = 100
return json.dumps(data)
Upvotes: 2