Sau*_*eti 6 producer amazon-kinesis boto3
如何使用 boto3 将数据从 csv 上传到 aws kinesis
我已经尝试了三种方法,这对我来说都很有效。
此外如何将kinesis中的数据消费到python sdk
import csv
import json
import boto3
from random import randint
def chunkit(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
kinesis = boto3.client("kinesis")
with open("flights.csv") as f:
#Creating the ordered Dict
reader = csv.DictReader(f)
#putting the json as per the number of chunk we will give in below function
#Create the list of json and push like a chunk. I am sending 100 rows together
records = chunkit([{"PartitionKey": 'sau', "Data": json.dumps(row)} for row in reader], 100)
for chunk in records:
kinesis.put_records(StreamName="Flight-Simulator", Records=chunk)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5719 次 |
| 最近记录: |