Возвращать записи JSON в одну строку, используя python 2.7 - PullRequest
0 голосов
/ 13 мая 2018

Я написал код, который принимает входные данные из aws Kinesis Stream и загружает его в корзину S3. Но он загружает все записи JSON в одну строку, мне нужна каждая запись JSON в отдельной строке. Ниже приведен код, нужна помощь в исправлении кода.

import base64
import json

print('Loading function')


def lambda_handler(event, context):
    print('input format json:',event['records'])
    output = []

    for record in event['records']:
        payload = base64.b64decode(record['data'])
        payload_2 = base64.b64decode(payload)
        sector = json.loads(payload_2)
        sector_dumps = json.dumps({'resourceType': sector['entry'][0]['resource']['resourceType'],
               'status':sector['entry'][0]['resource']['status'],
               'id': sector['entry'][0]['resource']['id'],
               'code': sector['entry'][0]['resource']['code']['coding'],
               'value': sector['entry'][0]['resource']['valueQuantity']['value'],
               'unit' : sector['entry'][0]['resource']['valueQuantity']['unit'],
               'effectiveDateTime':sector['entry'][0]['resource']['effectiveDateTime'],
               'subject':sector['entry'][0]['resource']['subject'],
               'performer':sector['entry'][0]['resource']['performer'],
               'category':sector['entry'][0]['resource']['category'],
              }, indent=0 )
        sector_byte = sector_dumps.encode("utf-8")
        sector_byte_encode = base64.b64encode(sector_byte)
        # Do custom processing on the record payload here
        output_record = {
            'recordId': record['recordId'],
            'result': 'Ok',
            'data': sector_byte_encode
        }
        output.append(output_record)

    print('Successfully processed {} records.'.format(len(event['records'])))
    return {'records': output}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...