2012-10-21

DynamoDB & Ruby

I played around with DynamoDB and Ruby and put down a small sample. Here is what you need to run this sample:

  1. Get yourself an AWS account. The access key id and the associated secret access key are to be stored in a YAML file called aws_config.yml with the following format:
    access_key_id: <your access key id>
    secret_access_key: <your secret access key>
  2. The AWS SDK for Ruby: Download and extract.
  3. A Ruby interpreter: The SDK requires Ruby 1.8.7 or later - I've run this sample with Ruby 1.9.3.
  4. Store the sample in a local file within the same directory as the YAML file and make it executable for convenience. Maybe you have to change the location of the AWS SDK for Ruby in line 5.
Here's a shot short outline of what the sample does:
  1. Setup the load path and load some required files.
  2. Create two tables, if they do not already exist - one with a hash key and one with a hash key and a range key. The sample waits until the tables have left the creating state.
  3. Create some items within these two tables. As DynamoDB is schema-less, you are free to store any information within these items - except for the keys you've defined, they are mandatory.
  4. After counting the items, a query and a scan is performed. A query uses the defined keys to return items, a scan runs through all items of a table.
  5. Wait 20 seconds and delete the two tables. The sample waits until the tables have left the deleting state.
It is notable that in DynamoDB tables take some time to be created and deleted. The sample takes this into account. You can watch the current state of your tables using the AWS console.

No comments:

Post a Comment