I am writing an AWS Lambda function that invokes another Lambda function. Both Lambda functions are in python. The called function returns a JSON, that gets wrapped into botocore.response.streamingbody. I am unable to convert this back to JSON to access the required fields.
Tried different links including:
p = r['Payload'].read()
print p #Prints an empty string
print(r['Payload'].read()) #Prints Just a string
invoke_lambda(payload)
and r['Payload'].read().decode()
r['Payload'].read().decode("utf-8")
Sample output from called Lambda function (got from printing the response before returning):
{'statusCode': 200, 'headers': {'Access-Control-Allow-Origin': ''}, 'body1': [{'statusCode': 200, 'body': {'featureId': 'testFeature', 'version': '2.1', 'active': True}, 'headers': {'Access-Control-Allow-Origin': ''}}]}
Response returned after calling this lambda from called Lambda function:
{u'Payload': , u'ExecutedVersion': '$LATEST', 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '0f10c74d-ebd7-4a8a-8992-6211a969ceb1', 'HTTPHeaders': {'x-amzn-requestid': '0f10c74d-ebd7-4a8a-8992-6211a969ceb1', 'content-length': '213', 'x-amz-executed-version': '$LATEST', 'x-amzn-trace-id': 'root=1-5d11c78f-f4d70afef2f04f3d061136fa;sampled=0', 'x-amzn-remapped-content-length': '0', 'connection': 'keep-alive', 'date': 'Tue, 25 Jun 2019 07:04:47 GMT', 'content-type': 'application/json'}}, u'StatusCode': 200}