Skip to content

Instantly share code, notes, and snippets.

@satour
Created January 17, 2017 10:49
Show Gist options
  • Save satour/c40735ccbd264f005bb59f7a72b5f7d1 to your computer and use it in GitHub Desktop.
Save satour/c40735ccbd264f005bb59f7a72b5f7d1 to your computer and use it in GitHub Desktop.
require "aws-sdk"
require "time"
item_size = ARGV[0].to_i
puts "you can set number of item to put with ARGV." unless ARGV
dynamodb = Aws::DynamoDB::Client.new
item_size.times {|i|
sleep rand(1..2)
t = Time.now
params = {
table_name: ARGV[1],
return_consumed_capacity: "TOTAL",
item: {
userId: "0001-0000-0017-0001-0001",
gender: t.to_i.even? ? "m" : "f",
age: rand(0..60),
datetime: t.to_s,
timestamp:t.to_i
}
}
begin
result = dynamodb.put_item(params)
puts "[#{i}]Put Item. #{result.consumed_capacity}"
rescue Aws::DynamoDB::Errors::ServiceError => error
puts "Unable to put item:"
puts "#{error.message}"
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment