Created
June 27, 2013 20:44
-
-
Save weavenet/5880251 to your computer and use it in GitHub Desktop.
Dynamo Ruby Sample
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'aws-sdk' | |
# create a table (10 read and 5 write capacity units) | |
dynamo_db = AWS::DynamoDB.new :region => 'us-west-2' | |
# get a table by name and specify its schema | |
table = dynamo_db.tables['dynamo-test'] | |
table.hash_key = ['Customer ID', :number] | |
item = table.items.create('Customer ID' => 12345, 'foo' => 'bar') | |
# add attributes to an item | |
1.upto(10).each do |c| | |
start_time = Time.now | |
item.attributes.set 'updated_at' => Time.now.to_i | |
write_time = Time.now | |
item.attributes['updated_at'].to_i | |
end_time = Time.now | |
puts "Write: #{((end_time - start_time) * 1000).to_i} ms" | |
end | |
# read attributes to an item | |
1.upto(10).each do |c| | |
start_time = Time.now | |
item = table.items[12345] | |
item.attributes['updated_at'] | |
end_time = Time.now | |
puts "Read: #{((end_time - start_time) * 1000).to_i} ms" | |
end | |
item.delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment