如何使用boto3将数据从python sdk上传到kinesis

Sau*_*eti 6 producer amazon-kinesis boto3

如何使用 boto3 将数据从 csv 上传到 aws kinesis

我已经尝试了三种方法,这对我来说都很有效。

  1. 将数据从 csv 分块上传到 kinesis。
  2. 将本地随机生成的数据上传到 kinesis。
  3. 使用 boto3 将 csv 数据从本地逐行上传到 kinesis

此外如何将kinesis中的数据消费到python sdk

Sau*_*eti 3

方法1 逐块

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)