我正在将数据从Kinesis Firehose发送到Lambda函数(在其当前的测试形式中,该函数只对有效负载进行解码和重新编码),然后将其转移到S3。该流程工作正常,但S3中的文件仅包含base64编码的blob。
这是推:
import boto3
import base64
client = boto3.client(
'firehose',
region_name = 'us-east-2'
)
push = {'id': '0142c979-e521-4e53-8bbe-1ac3281f0906', 'appId': 'b1fce1e293e4d0620041a76c6a70813c', 'deviceId': 'NEGL4CB15141K525', 'msgCode': 'location', 'type': 'keep', 'timestamp': 1561812470273, 'fields': {'location': [-73.9066, 40.682915]}}
string = json.dumps(push).encode()
payload = base64.b64encode(string)
client.put_record(
DeliveryStreamName='test'
,Record = {
'Data': payload
})
这是lambda:
from __future__ import print_function
import json
import base64
def lambda_handler(event, context):
output = []
for record in event['records']:
#Kinesis data is base64 encoded so decode here
payload=base64.b64decode(record['data']).decode('utf-8')
print("Decoded payload: " + str(payload))
output_record = {
'recordId': record['recordId'],
'result': 'Ok',
'data': base64.b64encode(payload.encode('utf-8') + b'\n').decode('utf-8')
}
output.append(output_record)
print('Successfully processed {} records.'.format(len(event['records'])))
return {'records': output}
我是Firehose的新手,并且几乎一直在拼凑我可以在网上找到的教程。我的理解是,这应该作为解码的JSON放在我的S3存储桶中,这样我就可以用Athena或其他我想做的查询。但在我的铲斗前端的文件最大编码(例如eyJpZCI6ICIwMTQyYzk3OS1lNTIxLTRlNTMtOGJiZS0xYWMzMjgxZjA5MDYiLCAiYXBwSWQiOiAiYjFmY2UxZTI5M2U0ZDA2MjAwNDFhNzZjNmE3MDgxM2MiLCAiZGV2aWNlSWQiOiAiTkVHTDRDQjE1MTQxSzUyNSIsICJtc2dDb2RlIjogImxvY2F0aW9uIiwgInR5cGUiOiAia2VlcCIsICJ0aW1lc3RhbXAiOiAxNTYxODEyNDcwMjczLCAiZmllbGRzIjogeyJsb2NhdGlvbiI6IFstNzMuOTA2NiwgNDAuNjgyOTE1XX19)
对于我在这里缺少的任何帮助,我们将不胜感激。