dynamodb-spring-boot
A simple wrapper for derjust's Spring Data DynamoDB.
Usage:
Add the dependency to your pom.xml
<dependency>
<groupId>com.github.elvisnovoa</groupId>
<artifactId>dynamodb-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
Then follow derjust's instructions to set up your repositories. For example, given a DynamoDB table named User
, we have the corresponding POJO:
@DynamoDBTable(tableName = "User")
public class User {
private String id;
private String firstName;
private String lastName;
public User() {}
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;
}
// setters omitted
}
...and the following Spring Data Repository.
public interface UserRepository extends CrudRepository<User, String> {
List<User> findByLastName(String lastName);
List<User> findByFirstName(String firstName);
}
Customizing
This autoconfigure project uses the default spring-data-dynamodb
configurations and reads any repositories in the same package of a @SpringBootApplication
. To use different configurations, you can create your own configuration class and annotate it with @EnableDynamoDBRepositories
. In that case, why are you using this?
The library also creates a com.amazonaws.services.dynamodbv2.AmazonDynamoDB
bean with default configurations, but you can provide your own. For example:
private AWSCredentialsProvider amazonAWSCredentialsProvider() {
return new AWSStaticCredentialsProvider(amazonAWSCredentials());
}
private AWSCredentials amazonAWSCredentials() {
return new BasicAWSCredentials("amazonAWSAccessKey", "amazonAWSSecretKey"); // Don't ever do this, plz
}
@Bean
public AmazonDynamoDB amazonDynamoDB() {
return AmazonDynamoDBClientBuilder.standard()
.withCredentials(amazonAWSCredentialsProvider())
.build();
}