Skip to content

Commit 4c912f5

Browse files
committed
Prepare for KCL Python Release 2.1.0
1 parent bc09d8b commit 4c912f5

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ all languages.
146146

147147
## Release Notes
148148

149+
### Release 2.1.0 (January 12, 2023)
150+
* Upgraded to use version 2.4.4 of the [Amazon Kinesis Client library][kinesis-github]
151+
149152
### Release 2.0.6 (November 23, 2021)
150153
* Upgraded multiple dependencies [PR #152](https://github.com/awslabs/amazon-kinesis-client-python/pull/152)
151154
* Amazon Kinesis Client Library 2.3.9

samples/sample_kinesis_wordputter.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,58 @@
44
SPDX-License-Identifier: Apache-2.0
55
'''
66
from __future__ import print_function
7-
import sys, random, time, argparse
8-
from boto import kinesis
97

10-
def get_stream_status(conn, stream_name):
8+
import argparse
9+
import sys
10+
import time
11+
12+
import boto3
13+
14+
def get_stream_status(kinesis, stream_name):
1115
'''
1216
Query this provided connection object for the provided stream's status.
13-
14-
:type conn: boto.kinesis.layer1.KinesisConnection
17+
:type conn: Kinesis.Client
1518
:param conn: A connection to Amazon Kinesis
16-
1719
:type stream_name: str
1820
:param stream_name: The name of a stream.
19-
2021
:rtype: str
2122
:return: The stream's status
2223
'''
23-
r = conn.describe_stream(stream_name)
24+
r = kinesis.describe_stream(StreamName=stream_name)
2425
description = r.get('StreamDescription')
2526
return description.get('StreamStatus')
2627

27-
def wait_for_stream(conn, stream_name):
28+
def wait_for_stream(kinesis, stream_name):
2829
'''
2930
Wait for the provided stream to become active.
30-
31-
:type conn: boto.kinesis.layer1.KinesisConnection
32-
:param conn: A connection to Amazon Kinesis
33-
31+
:type kinesis: Kinesis.Client
32+
:param kinesis: A low-level client representing Amazon Kinesis
3433
:type stream_name: str
3534
:param stream_name: The name of a stream.
3635
'''
3736
SLEEP_TIME_SECONDS = 3
38-
status = get_stream_status(conn, stream_name)
37+
status = get_stream_status(kinesis, stream_name)
3938
while status != 'ACTIVE':
4039
print('{stream_name} has status: {status}, sleeping for {secs} seconds'.format(
4140
stream_name = stream_name,
4241
status = status,
4342
secs = SLEEP_TIME_SECONDS))
4443
time.sleep(SLEEP_TIME_SECONDS) # sleep for 3 seconds
45-
status = get_stream_status(conn, stream_name)
44+
status = get_stream_status(kinesis, stream_name)
4645

47-
def put_words_in_stream(conn, stream_name, words):
46+
def put_words_in_stream(kinesis, stream_name, words):
4847
'''
4948
Put each word in the provided list of words into the stream.
50-
51-
:type conn: boto.kinesis.layer1.KinesisConnection
52-
:param conn: A connection to Amazon Kinesis
53-
49+
:type kinesis: Kinesis.Client
50+
:param kinesis: A connection to Amazon Kinesis
5451
:type stream_name: str
5552
:param stream_name: The name of a stream.
56-
5753
:type words: list
5854
:param words: A list of strings to put into the stream.
5955
'''
6056
for w in words:
6157
try:
62-
conn.put_record(stream_name, w, w)
58+
kinesis.put_record(StreamName=stream_name, Data=w, PartitionKey=w)
6359
print("Put word: " + w + " into stream: " + stream_name)
6460
except Exception as e:
6561
sys.stderr.write("Encountered an exception while trying to put a word: "
@@ -69,16 +65,12 @@ def put_words_in_stream_periodically(conn, stream_name, words, period_seconds):
6965
'''
7066
Puts words into a stream, then waits for the period to elapse then puts the words in again. There is no strict
7167
guarantee about how frequently we put each word into the stream, just that we will wait between iterations.
72-
7368
:type conn: boto.kinesis.layer1.KinesisConnection
7469
:param conn: A connection to Amazon Kinesis
75-
7670
:type stream_name: str
7771
:param stream_name: The name of a stream.
78-
7972
:type words: list
8073
:param words: A list of strings to put into the stream.
81-
8274
:type period_seconds: int
8375
:param period_seconds: How long to wait, in seconds, between iterations over the list of words.
8476
'''
@@ -90,10 +82,8 @@ def put_words_in_stream_periodically(conn, stream_name, words, period_seconds):
9082
if __name__ == '__main__':
9183
parser = argparse.ArgumentParser('''
9284
Puts words into a stream.
93-
9485
# Using the -w option multiple times
9586
sample_wordputter.py -s STREAM_NAME -w WORD1 -w WORD2 -w WORD3 -p 3
96-
9787
# Passing input from STDIN
9888
echo "WORD1\\nWORD2\\nWORD3" | sample_wordputter.py -s STREAM_NAME -p 3
9989
''')
@@ -115,25 +105,26 @@ def put_words_in_stream_periodically(conn, stream_name, words, period_seconds):
115105
one of the standard credentials providers.
116106
'''
117107
print("Connecting to stream: {s} in {r}".format(s=stream_name, r=args.region))
118-
conn = kinesis.connect_to_region(region_name = args.region)
108+
kinesis = boto3.client('kinesis', region_name=args.region)
109+
119110
try:
120-
status = get_stream_status(conn, stream_name)
111+
status = get_stream_status(kinesis, stream_name)
121112
if 'DELETING' == status:
122113
print('The stream: {s} is being deleted, please rerun the script.'.format(s=stream_name))
123114
sys.exit(1)
124115
elif 'ACTIVE' != status:
125-
wait_for_stream(conn, stream_name)
116+
wait_for_stream(kinesis, stream_name)
126117
except:
127118
# We'll assume the stream didn't exist so we will try to create it with just one shard
128-
conn.create_stream(stream_name, 1)
129-
wait_for_stream(conn, stream_name)
119+
kinesis.create_stream(StreamName=stream_name, ShardCount=1)
120+
wait_for_stream(kinesis, stream_name)
130121
# Now the stream should exist
131122
if len(args.words) == 0:
132123
print('No -w options provided. Waiting on input from STDIN')
133124
words = [l.strip() for l in sys.stdin.readlines() if l.strip() != '']
134125
else:
135126
words = args.words
136127
if args.period != None:
137-
put_words_in_stream_periodically(conn, stream_name, words, args.period)
128+
put_words_in_stream_periodically(kinesis, stream_name, words, args.period)
138129
else:
139-
put_words_in_stream(conn, stream_name, words)
130+
put_words_in_stream(kinesis, stream_name, words)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
PACKAGE_NAME = 'amazon_kclpy'
4444
JAR_DIRECTORY = os.path.join(PACKAGE_NAME, 'jars')
45-
PACKAGE_VERSION = '2.0.6'
45+
PACKAGE_VERSION = '2.1.0'
4646
PYTHON_REQUIREMENTS = [
4747
'boto',
4848
# argparse is part of python2.7 but must be declared for python2.6

0 commit comments

Comments
 (0)