Simplifies the development of creating an Amazon DynamoDB-based Java data access layer
Pull request Compare This branch is 58 commits ahead of michaellavelle:master. Build Status Maven Central

Spring Data DynamoDB

The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use data access technologies. This module deals with enhanced support for Amazon DynamoDB based data access layers.

Supported Features

  • Implementation of CRUD methods for DynamoDB Entities
  • Dynamic query generation from query method names (Only a limited number of keywords and comparison operators currently supported)
  • Possibility to integrate custom repository code
  • Easy Spring annotation based integration

Demo application

For a demo of spring-data-dynamodb, using spring-data-rest to showcase DynamoDB repositories exposed with REST, please see spring-data-dynamodb-demo.

Version & Spring Framework compatibility

The major and minor number of this library refers to the compatible Spring framework version. The build number is used as specified by SEMVER.

API changes will follow SEMVER and loosly the Spring Framework releases.

spring-data-dynamodb version Spring Framework compatibility Spring Data compatibility
1.0.x >= 3.1 && < 4.2
4.2.x >= 4.2 && < 4.3 Gosling-SR1
4.3.x >= 4.3 Gosling-SR1
4.4.x >= 4.3 Hopper-SR2
4.5.x >= 4.3 Ingalls

spring-data-dynamodb depends directly on spring-data as also spring-context, spring-data and spring-tx.

compile and runtime dependencies are kept to a minimum to allow easy integartion, for example into Spring-Boot projects.

Quick Start

Download the JAR though Maven:


or via Gradle

repositories {

dependencies {
  compile group: 'com.github.derjust',
  name: 'spring-data-dynamodb',
  version: '4.5.0'

Setup DynamoDB configuration as well as enabling Spring Data DynamoDB repository support.

@EnableDynamoDBRepositories(basePackages = "com.acme.repositories")
public class DynamoDBConfig {

    private String amazonDynamoDBEndpoint;

    private String amazonAWSAccessKey;

    private String amazonAWSSecretKey;

    public AmazonDynamoDB amazonDynamoDB(AWSCredentials amazonAWSCredentials) {
        AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient(amazonAWSCredentials);

        if (StringUtils.isNotEmpty(amazonDynamoDBEndpoint)) {
        return amazonDynamoDB;

    public AWSCredentials amazonAWSCredentials() {
        // Or use an AWSCredentialsProvider/AWSCredentialsProviderChain
        return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);


or in XML...

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

  <bean id="amazonDynamoDB" class="">
    <constructor-arg ref="amazonAWSCredentials" />
    <property name="endpoint" value="${amazon.dynamodb.endpoint}" />

  <bean id="amazonAWSCredentials" class="com.amazonaws.auth.BasicAWSCredentials">
    <constructor-arg value="${}" />
    <constructor-arg value="${}" />

  <dynamodb:repositories base-package="com.acme.repositories" amazon-dynamodb-ref="amazonDynamoDB" />


Create a DynamoDB hash-key only table in AWS console, with table name User and with hash key attribute name id.

Create a DynamoDB entity for this table:

@DynamoDBTable(tableName = "User")
public class User {

  private String id;
  private String firstName;
  private String lastName;

  public User() {

  public String getId() {
    return id;

  public String getFirstName() {
    return firstName;

  public String getLastName() {
    return lastName;

  public void setId(String id) { = id;

  public void setFirstName(String firstName) {
    this.firstName = firstName;

  public void setLastName(String lastName) {
    this.lastName = lastName;

  public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      User user = (User) o;

      return id.equals(;

  public int hashCode() {
      return id.hashCode();

Create a CRUD repository interface in com.acme.repositories:

package com.acme.repositories;

public interface UserRepository extends CrudRepository<User, String> {
  List<User> findByLastName(String lastName);

or for paging and sorting...

package com.acme.repositories;

public interface UserRepository extends PagingAndSortingRepository<User, String> {
  Page<User> findByLastName(String lastName,Pageable pageable);

  public Page<User> findAll(Pageable pageable);

And finally write a test client

@SpringApplicationConfiguration(classes = { 
    PropertyPlaceholderAutoConfiguration.class, DynamoDBConfig.class})
    public class UserRepositoryIntegrationTest {

    private static final String KEY_NAME = "id";
    private static final Long READ_CAPACITY_UNITS = 5L;
    private static final Long WRITE_CAPACITY_UNITS = 5L;

    UserRepository repository;

    private AmazonDynamoDB amazonDynamoDB;

    public void init() throws Exception {

        ListTablesResult listTablesResult = amazonDynamoDB.listTables();

                filter(tableName -> tableName.equals(User.TABLE_NAME)).forEach(tableName -> {

        List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName(KEY_NAME).withAttributeType("S"));

        List<KeySchemaElement> keySchemaElements = new ArrayList<KeySchemaElement>();
        keySchemaElements.add(new KeySchemaElement().withAttributeName(KEY_NAME).withKeyType(KeyType.HASH));

        CreateTableRequest request = new CreateTableRequest()
                .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(READ_CAPACITY_UNITS)



    public void sampleTestCase() {
        User dave = new User("Dave", "Matthews");;

        User carter = new User("Carter", "Beauford");;

        List<User> result = repository.findByLastName("Matthews");
        Assert.assertThat(result.size(), is(1));
        Assert.assertThat(result, hasItem(dave));

Advanced topics

Advanced topics can be found in the wiki.

Release process

Check pom.xml for the proper <version />, afterwards execute

  $ mvn release:prepare && mvn release:perform

which will tag, build, test and upload the artifacts to Sonatype's OSS staging area.

Then visit and close the staging repository.

Afterwards release the staging repository. This will sync with Maven Central (give it some hours to become visible via