Created
August 28, 2014 10:04
-
-
Save n-shinya/857375ab0bb7fb8984e8 to your computer and use it in GitHub Desktop.
kinesis_put.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws-sdk' | |
print "Enter target stream name: " | |
stream_name = gets.chomp | |
begin | |
client = AWS::Kinesis.new( | |
access_key_id: ENV['AWS_ACCESS_KEY_ID'], | |
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'] | |
).client | |
categories = %w{Foods Books Toys Electronics Sports Clothing Shoes Music} | |
loop do | |
now = Time.now.to_s | |
partition_key = categories.sample | |
response = client.put_record( | |
stream_name: stream_name, | |
data: now, | |
partition_key: partition_key | |
) | |
puts "Data: #{now}, Partition Key: #{partition_key}, Shard ID: #{response.shard_id}, Seq Number: #{response.sequence_number}" | |
p response | |
sleep 1 | |
end | |
rescue => e | |
puts "Error: #{e.message}" | |
abort | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment