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 a data access layer built on AWS DynamoDB.

License

License

Categories

Categories

Data
GroupId

GroupId

com.github.derjust
ArtifactId

ArtifactId

spring-data-dynamodb
Last Version

Last Version

5.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

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 a data access layer built on AWS DynamoDB.
Project URL

Project URL

https://github.com/derjust/spring-data-dynamodb
Source Code Management

Source Code Management

https://github.com/derjust/spring-data-dynamodb

Download spring-data-dynamodb

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.derjust/spring-data-dynamodb/ -->
<dependency>
    <groupId>com.github.derjust</groupId>
    <artifactId>spring-data-dynamodb</artifactId>
    <version>5.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.derjust/spring-data-dynamodb/
implementation 'com.github.derjust:spring-data-dynamodb:5.1.0'
// https://jarcasting.com/artifacts/com.github.derjust/spring-data-dynamodb/
implementation ("com.github.derjust:spring-data-dynamodb:5.1.0")
'com.github.derjust:spring-data-dynamodb:jar:5.1.0'
<dependency org="com.github.derjust" name="spring-data-dynamodb" rev="5.1.0">
  <artifact name="spring-data-dynamodb" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.derjust', module='spring-data-dynamodb', version='5.1.0')
)
libraryDependencies += "com.github.derjust" % "spring-data-dynamodb" % "5.1.0"
[com.github.derjust/spring-data-dynamodb "5.1.0"]

Dependencies

compile (6)

Group / Artifact Type Version
org.springframework : spring-context jar
org.springframework : spring-tx jar
org.springframework.data : spring-data-commons jar 2.1.2.RELEASE
org.hibernate.validator : hibernate-validator jar 6.0.9.Final
com.amazonaws : aws-java-sdk-dynamodb jar
javax.enterprise : cdi-api jar 1.2

test (6)

Group / Artifact Type Version
org.springframework : spring-test jar
com.amazonaws » DynamoDBLocal jar [1.11,2.0)
org.apache.logging.log4j : log4j-to-slf4j jar 2.8.2
junit : junit jar 4.12
org.mockito : mockito-core jar 2.23.0
uk.org.lidalia : slf4j-test jar 1.2.0

Project Modules

There are no modules declared in this project.

codecov.io Build Status Maven Central Developer Workspace Donation badge

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 a data access layer built on AWS DynamoDB.

Technical infos can be found on the project page.

Supported Features

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-examples.

Quick Start

Download the JAR though Maven Central (SNAPSHOT builds are available via the OSSRH snapshot repository ):

<dependency>
  <groupId>com.github.derjust</groupId>
  <artifactId>spring-data-dynamodb</artifactId>
  <version>5.1.0</version>
</dependency>

Setup DynamoDB configuration as well as enabling Spring-Data DynamoDB repository support via Annotation (XML-based configuration)

Create a DynamoDB entity User for this table:

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

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

	public User() {
		// Default constructor is required by AWS DynamoDB SDK
	}

	public User(String firstName, String lastName) {
		this.firstName = firstName;
		this.lastName = lastName;
	}

	@DynamoDBHashKey
	@DynamoDBAutoGeneratedKey
	public String getId() {
		return id;
	}

	@DynamoDBAttribute
	public String getFirstName() {
		return firstName;
	}

	@DynamoDBAttribute
	public String getLastName() {
		return lastName;
	}

	//setter & hashCode & equals
}

Create a CRUD repository interface UserRepository:

@EnableScan
public interface UserRepository extends CrudRepository<User, String> {
  List<User> findByLastName(String lastName);
  List<User> findByFirstName(String firstName);
}

or for paging and sorting...

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

	@EnableScan
	@EnableScanCount
	Page<User> findAll(Pageable pageable);
}

Create the configuration class DynamoDBConfig:

@Configuration
@EnableDynamoDBRepositories(basePackageClasses = UserRepository.class)
public static class DynamoDBConfig {

	@Value("${amazon.aws.accesskey}")
	private String amazonAWSAccessKey;

	@Value("${amazon.aws.secretkey}")
	private String amazonAWSSecretKey;

	public AWSCredentialsProvider amazonAWSCredentialsProvider() {
		return new AWSStaticCredentialsProvider(amazonAWSCredentials());
	}

	@Bean
	public AWSCredentials amazonAWSCredentials() {
		return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);
	}

	@Bean
	public DynamoDBMapperConfig dynamoDBMapperConfig() {
		return DynamoDBMapperConfig.DEFAULT;
	}

	@Bean
	public DynamoDBMapper dynamoDBMapper(AmazonDynamoDB amazonDynamoDB, DynamoDBMapperConfig config) {
		return new DynamoDBMapper(amazonDynamoDB, config);
	}

	@Bean
	public AmazonDynamoDB amazonDynamoDB() {
		return AmazonDynamoDBClientBuilder.standard().withCredentials(amazonAWSCredentialsProvider())
				.withRegion(Regions.US_EAST_1).build();
	}
}

And finally write a test client UserRepositoryIT or start calling it from your existing Spring code.

The full source code is available at spring-data-dynamodb-examples' simple example

More

More sample code can be found in the spring-data-dynamodb-examples project.

Advanced topics can be found in the wiki.

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 Boot compatibility Spring Framework compatibility Spring Data compatibility
1.0.x >= 3.1 && < 4.2
4.2.x >= 1.3.0 && < 1.4.0 >= 4.2 && < 4.3 Gosling-SR1
4.3.x >= 1.4.0 && < 2.0 >= 4.3 && < 5.0 Gosling-SR1
4.4.x >= 1.4.0 && < 2.0 >= 4.3 && < 5.0 Hopper-SR2
4.5.x >= 1.4.0 && < 2.0 >= 4.3 && < 5.0 Ingalls
5.0.x >= 2.0 && < 2.1 >= 5.0 && < 5.1 Kay-SR1
5.1.x >= 2.1 >= 5.1 Lovelace-SR1
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.

History

The code base has some history already in it - let's clarify it a bit:

The Java package name/XSD namespace never changed from org.socialsignin.spring.data.dynamodb. But the XSD is now also available at https://derjust.github.io/spring-data-dynamodb/spring-dynamodb-1.0.xsd.

Versions

Version
5.1.0
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
4.5.7
4.5.6
4.5.5
4.5.4
4.5.3
4.5.2
4.5.1
4.5.0
4.4.1
4.3.1
4.3.0
4.2.3
4.2.0
1.0.5