Lambda Return Payload botocore.response.StreamingBody object prints but then empty in variable
The following code solves the problem. Apparently I need to set the streamingbody to a variable, then read it into another variable. I used this link for reference
def invoke_lambda(payload):
r = lambda_client.invoke(
FunctionName='MyLambdaFunction',
InvocationType='RequestResponse',
Payload=bytes(payload)
)
t = r['Payload']
j = t.read()
print j
If you expect JSON as response, you can do the following:
import json
def invoke_lambda(payload):
response = lambda_client.invoke(
FunctionName='MyLambdaFunction',
InvocationType='RequestResponse',
Payload=bytes(payload)
)
response_payload = json.loads(invoke_response['Payload'].read().decode("utf-8"))
print ("response_payload: {}".format(response_payload))