- 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>
- The AWS SDK for Ruby: Download and extract.
- A Ruby interpreter: The SDK requires Ruby 1.8.7 or later - I've run this sample with Ruby 1.9.3.
- 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:
- Setup the load path and load some required files.
- 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.
- 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.
- 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.
- 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.