AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to generate sample data for the RANDOM_CUT_FOREST SQL function.

# Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import json import boto3 import random kinesis = boto3.client('kinesis') # generate normal heart rate with probability .99 def getNormalHeartRate(): data = {} data['heartRate'] = random.randint(60, 100) data['rateType'] = "NORMAL" return data # generate high heart rate with probability .01 (very few) def getHighHeartRate(): data = {} data['heartRate'] = random.randint(150, 200) data['rateType'] = "HIGH" return data while True: rnd = random.random() if (rnd < 0.01): data = json.dumps(getHighHeartRate()) print(data) kinesis.put_record( StreamName="ExampleInputStream", Data=data, PartitionKey="partitionkey") else: data = json.dumps(getNormalHeartRate()) print(data) kinesis.put_record( StreamName="ExampleInputStream", Data=data, PartitionKey="partitionkey")

Sample Details

Service: kinesisanalytics

Last tested: 2019-01-29

Author: fletpatr (AWS)

Type: full-example

On this page: