Since I am now an Amazonian, I thought it would be a good time to start learning how to use our technologies. So, here it is: the first instalment in my new, occasional series, which I am tentatively calling “AWS via Haskell”. In these posts we’ll do AWS stuff using our programming language of choice, i.e. Haskell. I will build these examples on top of the awesome and comprehensive amazonka family of packages by Brendan Hay.

Today, I’ll talk about how to do some basic tasks with DynamoDB.

Part 1: Prerequisites

You’ll need access to a DynamoDB instance. The two most common ways of doing this are as follows:

Create an AWS account and use your DynamoDB instance in the cloud: you can start with the free tier and go from there

Download and install DynamoDB locally

Part 2: dynamodb-demo.cabal : the dependencies

This examples use the following standard Haskell packages which do not require additional explanation:

bytestring

lens

resourcet

text

unordered-containers

In addition, we depend on the following amazonka packages:

amazonka : connection and credential handling etc.

: connection and credential handling etc. amazonka-dynamodb : DynamoDB-specific APIs

Part 3: Main.hs : the code

This simple program demonstrates the core tasks you’ll most likely find yourself doing with DynamoDB:

Creating tables

Deleting tables

Putting items

Getting items

Updating items

The things of most note are as follows:

amazonka APIs make heavy use of lenses

The DynamoDB APIs make heavy use of HashMap s

s Expensive operations such as creation and deletion of tables are asynchronous and amazonka provides access to the native AWS “waiter” APIs to simplify polling for these kinds of operation to complete

Part 4: The full working demo project

I’ve gathered this all together into this buildable project. As always, I like to build using Stack.

Part 5: Related posts