Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Kinesis Client put_record

import boto3
import json
from datetime import datetime
import calendar
import random
import time

my_stream_name = 'python-stream'

kinesis_client = boto3.client('kinesis', region_name='us-east-1')

def put_to_stream(thing_id, property_value, property_timestamp):
    payload = {
                'prop': str(property_value),
                'timestamp': str(property_timestamp),
                'thing_id': thing_id
              }

    print payload

    put_response = kinesis_client.put_record(
                        StreamName=my_stream_name,
                        Data=json.dumps(payload),
                        PartitionKey=thing_id)

while True:
    property_value = random.randint(40, 120)
    property_timestamp = calendar.timegm(datetime.utcnow().timetuple())
    thing_id = 'aa-bb'

    put_to_stream(thing_id, property_value, property_timestamp)

    # wait for 5 second
    time.sleep(5)
Comment

PREVIOUS NEXT
Code Example
Python :: var person 
Python :: new line in jupyter notebook markdown 
Python :: numpy.where() for substring 
Python :: pagerank formula 
Python :: while attempts 0: 
Python :: how to make an infinite loop in python 
Python :: onetoone vs foreign key django 
Python :: asyncio RuntimeError: Event loop is closed 
Python :: grading system in python with nested if 
Python :: run exe for python and wait until finish 
Python :: slug in redirect django 
Python :: label default text value python 
Python :: adding text on barplot using seabron 
Python :: check if number is divisible without remainder python 
Python :: python keyboard monitoring 
Python :: box detection 
Python :: Print in python capital p 
Python :: divide array into equal parts/slices python 
Python :: Compute Jordan normal form of matrix in Python / NumPy 
Python :: Reason: "broken data stream when reading image file" in jupyter notebook 
Python :: python pipe select where 
Python :: create animation from sequence of image python 
Python :: Walrus operator in list comprehensions [Python 3.8.0] 
Python :: print hello in python 
Python :: pandas read csv read all columns except few columns 
Python :: pandas df where 
Python :: python open application 
Python :: python index 
Python :: if else condition python 
Python :: python difference 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =