使用python Labmda函数从dynamodb流中检索字段值

时间:2019-01-29 10:15:41

标签: python-2.7 aws-lambda amazon-dynamodb-streams

在下面的代码中,print语句不返回任何内容。

import boto3
import json
import os

# Initiate Firehose client
firehose_client = boto3.client('firehose')

def lambda_handler(event, context):
    records = []
    batch   = []
    try :
        for record in event['Records']:
            tweet = {}
            print(record['dynamodb']['Keys']['sentiment']['S'])
            t_stats = '{"sentiment":"%s", "totalnumber":"%n"}\n'\
                             % (record['dynamodb']['Keys']['sentiment']['S'],\
                             record['dynamodb']['totalnumber']['N'])
            tweet["Data"] = t_stats
            records.append(tweet)
        batch.append(records)
        res = firehose_client.put_record_batch(
            DeliveryStreamName = os.environ['firehose_stream_name'],
            Records = batch[0]
        )
        return 'Successfully processed {} records.'.format(len(event['Records']))
    except Exception :
        pass

0 个答案:

没有答案