When calling a Lambda Function via Boto3, the returned object is something like:
{u'Payload': <botocore.response.StreamingBody object at 0x7f8d5b62ac50>,
'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '5bdbb3ca-3b35-11e7-9816-397b140c3bac', 'HTTPHeaders': {'x-amzn-requestid': '5bdbb3ca-3b35-11e7-9816-397b140c3bac', 'content-length': '1636', 'x-amzn-trace-id': 'root=1-591ca199-00d34d5474d16275ec2c8d10;sampled=0', 'x-amzn-remapped-content-length': '0', 'connection': 'keep-alive', 'date': 'Wed, 17 May 2017 19:16:41 GMT', 'content-type': 'application/json'}}, u'StatusCode': 200}
The Payload
parameter is <botocore.response.StreamingBody>
which is a data streaming object.
import botocore.response as br
streaming_obj = br.StreamingBody(raw_stream=None,content_length=5000)
streaming_obj.read(amt=)
This is essentially a pointer to a data source that can be consumed as a stream via:
NUM_OF_BYTES = 1000
streaming.read(amt=NUM_OF_BYTES)
Or, if NUM_OF_BYTES == None
then it will return the entire stream.
This data has to be made available to other functions, so one approach is to convert to string:
string_data = streaming_obj.read().decode("utf-8")
Returning to our Lambda Function, then the streaming object is referenced via a Payload
parameter (see above) and typically we'd expect to see a JSON object (say):
res_json = json.loads(res['Payload'].read().decode("utf-8"))