Throw something to Kinesis with python and make sure it's in

things to do

  1. Throw "hogehoge" to Kinesis
  2. Check if "hogehoge" is included

Junbi

  1. Make Python available
  2. Install boto
  3. Create an account to play with Kinesis with IAM
  4. Create Stream and Shard which are the ports to receive data in Kinesis

By the way, this time the name of shard is "test" and the number is one.

Squeeze

Main.py


#-*- coding: utf-8 -*-

from boto import kinesis

auth = {"aws_access_key_id":"Please enter the IAM ACCESS KEY", "aws_secret_access_key":"Please enter the IAM SECRET ACCESS KEY"}

if __name__ == '__main__':
    #            kinesis.connect_to_region('region',IAM credentials)
    Connection = kinesis.connect_to_region('us-east-1',**auth)
    while true:
        #Write
        #             Connection.put_record(Stream name,Data to write, PartitionKey)
        put_response = Connection.put_record('test'    , "hogehoge"  , 'one')
        sleep(10)

only this.

View

A worker is attached to each shard to read the data so that it can be processed even if the shard increases.

show.py


# -*- coding: utf-8 -*-
 
import time
import base64
import multiprocessing
from boto import kinesis
import threading

auth = {"aws_access_key_id":"Please enter the IAM ACCESS KEY", "aws_secret_access_key":"Please enter the IAM SECRET ACCESS KEY"}

#The name of the stream
STREAM_NAME='test'
 
def worker(connect, kinesis_iterator):
    next_iterator = kinesis_iterator['ShardIterator']
    while True:
        response = connect.get_records(next_iterator)
        next_iterator = response['NextShardIterator']
        time.sleep(1)
        
        #Display the contents written in shard
        for data in response['Records']:
            print(data)
 
 
def get_record():
    connect = kinesis.connect_to_region('us-east-1',**auth)
    stream = connect.describe_stream(STREAM_NAME)
    #Get a list of shards
    shards = stream['StreamDescription']['Shards']

    #Install a worker for each shard and get data
    for shard in shards:
        kinesis_iterator = connect.get_shard_iterator(STREAM_NAME, shard['ShardId'], shard_iterator_type='TRIM_HORIZON')
        job = threading.Thread(target=worker, args=(connect, kinesis_iterator))
        job.start()
 
if __name__ == '__main__':
    get_record()

I was able to go like this.

Recommended Posts

Throw something to Kinesis with python and make sure it's in
Fractal to make and play with Python
Explain in detail how to make sounds with python
Something to enjoy with Prim Pro (X-Play) and Python
Try to make it using GUI and PyQt in Python
I tried to make GUI tic-tac-toe with Python and Tkinter
How to log in to AtCoder with Python and submit automatically
It's a hassle to write "coding: utf-8" in Python, so I'll do something with Shellscript
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
How to make a surveillance camera (Security Camera) with Opencv and Python
I tried to make a periodical process with Selenium and Python
Try logging in to qiita with Python
How to work with BigQuery in Python
Dealing with "years and months" in Python
Throw Incoming Webhooks to Mattermost in Python
To work with timestamp stations in Python
How to use is and == in Python
How to get the date and time difference in seconds with python
Try to make foldl and foldr with Python: lambda. Also time measurement
Scraping tabelog with python and outputting to CSV
MessagePack-Try to link Java and Python with RPC
[REAPER] How to play with Reascript in Python
How to generate permutations in Python and C ++
Convert PDFs to images in bulk with Python
I want to make a game with Python
Try to make a "cryptanalysis" cipher with Python
Send messages to Skype and Chatwork in Python
Log in to Yahoo Business with Selenium Python
How to use tkinter with python in pyenv
Try to make a dihedral group with Python
How to make Python Interpreter changes in Pycharm
To represent date, time, time, and seconds in Python
How to plot autocorrelation and partial autocorrelation in python
[# 1] Make Minecraft with Python. ~ Preliminary research and design ~
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
Try to make BOT by linking spreadsheet and Slack with python 2/2 (python + gspread + slackbot)
Try to make BOT by linking spreadsheet and Slack with python 1/2 (python + gspread + slackbot)
WEB scraping with python and try to make a word cloud from reviews
Convert timezoned date and time to Unixtime in Python2.7
Tool to make mask image for ETC in Python
How to convert / restore a string with [] in python
Procedure to load MNIST with python and output to png
Try to make a Python module in C language
Try to make a command standby tool with python
How to do hash calculation with salt in Python
I want to handle optimization with python and cplex
Make a simple Slackbot with interactive button in python
How to run tests in bulk with Python unittest
Try to operate DB with Python and visualize with d3
[# 2] Make Minecraft with Python. ~ Model drawing and player implementation ~
Operate Kinesis with Python
Convert the image in .zip to PDF with Python
Super Primer to python-Getting started with python3.5 in 3 minutes
It's too troublesome to display Japanese with Vim's python3.
I was addicted to scraping with Selenium (+ Python) in 2020
I want to work with a robot in python.
It's not easy to write Python, it's easy to write numpy and scipy
Find the Hermitian matrix and its eigenvalues in Python
Write tests in Python to profile and check coverage
[Note] How to write QR code and description in the same image with python
[Python] How to sort dict in list and instance in list