put_records() only accepts keyword arguments in Kinesis boto3 Python API

2024/10/7 2:21:44
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 = 0for question in questions:value1 = question['value']if value1 is None:value1 = '0'record = { 'StreamName':'LoadtestKinesis', 'Data':b'question','PartitionKey':'value1' }Records.append(record)count +=1if count == 500:response = client.put_records(Records)Records = []

This is my python script to load a array of json files to kinesis stream where I am combining 500 records to use put_records function . But I am getting an error: put_records() only accepts keyword arguments . How do I pass a list of Records to this method? Each record is a json with a partition key .

Sample 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"}]
Answer
    from __future__ import print_function # Python 2/3 compatibilityimport boto3import jsonimport decimalimport timedef putdatatokinesis(RecordKinesis):start = time.clock()response = client.put_records(Records=RecordKinesis, StreamName='LoadtestKinesis')print ("Time taken to process" +  len(Records) + " is " +time.clock() - start)return response
client = boto3.client('kinesis')
firehoseclient = boto3.client('firehose')
with open("questions.json") as json_file:questions = json.load(json_file)Records = []RecordKinesis = []count = 0for question in questions:value1 = question['value']if value1 is None:value1 = '0'recordkinesis = { 'Data':b'question','PartitionKey':value1 }RecordKinesis.append(recordkinesis)Records.append(record)count +=1if count == 500:putdatatokinesis(RecordKinesis)Records = []RecordKinesis = []

This worked , The idea is to pass the argument Records as a keyed argument .

https://en.xdnf.cn/q/70298.html

Related Q&A

Setting a transparent main window

How to set main window background transparent on QT? Do I need an attribute or a style? Ive tried setting the opacity, but it didnt work for me. app.setStyleSheet("QMainWindow {opacity:0}"

Elementwise division of sparse matrices, ignoring 0/0

I have two sparse matrices E and D, which have non-zero entries at the same places. Now I want to have E/D as a sparse matrix, defined only where D is non-zero.For example take the following code:impor…

Django import export Line number: 1 - uColumn id not found

I am trying to import excel documents into a Django DB. I have added the following code to admin.py and model.py. There seems to be an error in the development of Django. I have read through several di…

Why cant I access builtins if I use a custom dict as a functions globals?

I have a dict subclass like this:class MyDict(dict):def __getitem__(self, name):return globals()[name]This class can be used with eval and exec without issues:>>> eval(bytearray, MyDict()) <…

How to enable autocomplete (IntelliSense) for python package modules?

This question is not about Pygame, Im usin Pygame as an example.While experimenting with Pygame Ive noticed that autocomplete is not working for some modules. For example, if I start typing pygame.mixe…

Integrating a redirection-included method of payment in django-oscar

I am developing a shopping website using django-oscar framework, in fact I am using their sandbox site. I want to add payment to the checkout process, but the thing is, I am totally confused!Ive read t…

How can I unpack sequence?

Why cant I do this:d = [x for x in range(7)] a, b, c, d, e, f, g = *dWhere is it possible to unpack? Only between parentheses of a function?

Can I statically link Cython modules into an executable which embeds python?

I currently have an executable compiled from C++ that embeds python. The embedded executable runs a python script which load several Cython modules. Both the Cython modules and the executable are lin…

How to Store Graphs?

Lets say i have a class Graph defined.graph iowa = {.....nodes:{edges.......}}and similar graph clusters.once the script is running its all in the object. But how do you store the Graph info (including…

regex for only numbers in string?

I cant find the regex for strings containing only whitespaces or integers. The string is an input from user on keyboard. It can contain everything but \n (but it doesnt matter I guess), but we can focu…