You have a Json One line file in Kinesis and you want to split it to lines
- bdata3
- Feb 10, 2020
- 1 min read
Add the following lambda to handle the stream data, and this will add new line '\n' to each line:
from __future__ import print_function
import base64
import json
print('Loading function')
def lambda_handler(event, context):
output = []
for record in event['records']:
print(record['recordId'])
payload = base64.b64decode(record['data'])
# payload = msgpack.unpackb(base64.b64decode(record['data']), raw=False)
print(payload)
payload=payload + b'\n'
output_record = {
'recordId': record['recordId'],
'result': 'Ok',
# 'data':base64.b64encode(json.dumps(payload).encode('utf-8') ).decode('utf-8')
'data': base64.b64encode(payload).decode('utf-8')
}
output.append(output_record)
print('Successfully processed {} records.'.format(len(event['records'])))
return {'records': output}
Comments