from __future__ import print_function # Python 2/3 compatibility
import boto3
import json
import decimal
#kinesis = boto3.resource('kinesis', region_name='eu-west-1')
client = boto3.client('kinesis')
with open("questions.json") as json_file:
questions = json.load(json_file)
Records = []
count = 0
for question in questions:
value1 = question['value']
if value1 is None:
value1 = '0'
record = { 'StreamName':'LoadtestKinesis', 'Data':b'question','PartitionKey':'value1' }
Records.append(record)
count +=1
if count == 500:
response = client.put_records(Records)
Records = []
这是我的python脚本,用于将一个json文件数组加载到kinisis stream中,在这里我组合500个记录以使用put_records
函数。但是我得到一个错误:put_records() only accepts keyword arguments
。如何将记录列表传递给此方法?每个记录都是一个带有分区键的json。
示例Json:
[{
"air_date": "2004-12-31",
"answer": "FDDDe",
"category": "AACC",
"question": "'No. 2: 1912 Olympian; football star at Carlisle Indian School; 6 MLB seasons with the Reds, Giants & Braves'",
"round": "DDSSS!",
"show_number": "233",
"value": "$200"
}]
这样做有效,其思想是将参数记录作为键控参数传递。
传递多个记录时,需要将记录封装在记录列表中,然后添加流标识符。
格式如下:
有关详细信息,请参见Kinesis docs。
相关问题 更多 >
编程相关推荐