Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (65 sloc) 4.06 KB

Alternator - A DynamoDB Mock Server


While working on a new startup called Tivity, my co-worker, Thomas, and I found that testing simple functions with DynamoDB was a pain because it would take time to create testing tables and tear them back down. This would slow down our BDD approach to this project. Another nuisance was the cost that would incur when using DynamoDB from our local webapp or that we would hit our throughput limit and cause an error. Of course, this also means that you couldn't code things on the road because you needed an internet connect for Amazon Web Services.

To fix this, we've created a local data-store used for testing and development purposes by replicating DynamoDB's functionality. Our goal is to simplify the development and testing of DynamoDB specific functionality.

You can now add the dependency into your maven project with:

        <version><!-- ALTERNATOR VERSION (look in pom.xml to find version) --></version>

To get started, you need a 2 things: AlternatorDB (the service) and AlternatorDBClient (The client that calls the service). You can use DynamoDBMapper as long as the AlternatorDBClient is specified within it. The AlternatorDBClient is needed to circumvent the authentication process to AWS.

As a very simple example, you could do something like this in a test class:

public class AlternatorTest {

    private AlternatorDBClient client;
    private DynamoDBMapper mapper;
    private AlternatorDB db;

    public void setUp() throws Exception {
        this.client = new AlternatorDBClient();
        this.mapper = new DynamoDBMapper(this.client);
        this.db = new AlternatorDB().start();

    public void tearDown() throws Exception {

    public void test() {
        // Add test here that uses the mapper or the client

The AlternatorDB service defaults to port 9090, but can be changed in the constructor. If you change the port for the service, you also need to change the port to the client by using the setEndpoint function.

Of course, it's not always possible to just create the client, mapper and service within the test. If you're using the mapper and client in other parts of the system, you need a way to test that piece of code as well while replacing the client with the new one. If you're injecting the client within your code, be sure to inject the interface AmazonDynamoDB and not the implementation AmazonDynamoDBClient to leave the client interchangeable. You then simply need to use the test context, here's ours:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    <bean id="dynamoDBClient" class="com.michelboudreau.alternator.AlternatorDBClient"/>
    <bean id="dynamoDBMapper" class="">
        <constructor-arg index="0" ref="dynamoDBClient"/>

Then you only need to create the AlternatorDB service in your test and you're ready to test out your code. Hope this helps out. Please feel free to contribute or suggest ways to make the project better.

Jump to Line
Something went wrong with that request. Please try again.