Last active
March 6, 2017 17:53
-
-
Save SundeepK/4ffff773f92e3a430481 to your computer and use it in GitHub Desktop.
Simple example of how to use Local dynamodb with Ruby
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
#!/bin/bash | |
#Assuming you have downloading dynamoDBLocal and extracted into a dir called dynamodbLocal | |
java -Djava.library.path=./dynamodbLocal/DynamoDBLocal_lib -jar ./dynamodbLocal/DynamoDBLocal.jar -inMemory -port 9010 |
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
require 'aws-sdk-core' | |
dynamo_db = Aws::DynamoDB::Client.new(region: "eu-west-1", endpoint: 'http://localhost:9010') | |
dynamo_db.create_table({ | |
table_name: 'TestDB', | |
attribute_definitions: [{ | |
attribute_name: 'SomeKey', | |
attribute_type: 'S' | |
}, | |
{ | |
attribute_name: 'epochMillis', | |
attribute_type: 'N' | |
} | |
], | |
key_schema: [{ | |
attribute_name: 'SomeKey', | |
key_type: 'HASH' | |
}, | |
{ | |
attribute_name: 'epochMillis', | |
key_type: 'RANGE' | |
} | |
], | |
provisioned_throughput: { | |
read_capacity_units: 5, | |
write_capacity_units: 5 | |
} | |
}) | |
dynamo_db.put_item( table_name: "TestDB", | |
item: { | |
"SomeKey" => "somevalue1", | |
"epochMillis" => 1 | |
}) | |
puts dynamo_db.get_item({ | |
table_name: "TestDB", | |
key: { | |
"SomeKey" => "somevalue", | |
"epochMillis" => 1 | |
}}).item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment