This repository uses Java, SpringBoot with DynamoDB
-
Run
mvn verify
-
Test can be run with a local in-memory DynamoDB
-
To use a DynamoDb is necessary to update the aws properties in the file
src/main/resources/applications.properties
amazon.dynamodb.endpoint=http://localhost:8000/ amazon.aws.accesskey=<KEY> amazon.aws.secretkey=<SECRET_KEY> amazon.aws.region=<REGION>
-
Rest endpoints
- POST: http://localhost:8080/api/books: Add a new BookInfo
- GET: http://localhost:8080/api/books/{id}: Get a BookInfo by id
- GET: http://localhost:8080/api/books/: Get all BookInfos
In this repository to use DynamoDb in Java, it is necessary to add some dependencies, create a DynamoDB Configuration class, and use annotations in the entity classes
com.amazonaws::aws-java-sdk-dynamodb
io.github.boostchicken::spring-data-dynamodb
com.amazonaws::DynamoDBLocal
sqlite4java
depending on the Operative System
com.almworks.sqlite4java::sqlite4java
com.almworks.sqlite4java::sqlite4java-win32-x86
com.almworks.sqlite4java::sqlite4java-win32-x64
com.almworks.sqlite4java::libsqlite4java-osx
com.almworks.sqlite4java::libsqlite4java-linux-i386
com.almworks.sqlite4java::libsqlite4java-linux-amd64
A bean with the name amazonDynamoDB
is required, this bean manages the connection with the DynamoDB instance.
@Bean
public AmazonDynamoDB amazonDynamoDB() {
AmazonDynamoDB amazonDynamoDB
= AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration (amazonDynamoDBEndpoint, amazonAWSRegion) )
.withCredentials(new AWSStaticCredentialsProvider( new BasicAWSCredentials( amazonAWSAccessKey, amazonAWSSecretKey)))
.build();
return amazonDynamoDB;
}
The class is annotated to define it as a DynamoDB table
@DynamoDBTable(tableName = "BookInfo")
public class BookInfo {
Then, a key
@DynamoDBHashKey
@DynamoDBAutoGeneratedKey
public String getId() {
return id;
}
And finally, each attribute
@DynamoDBAttribute
public String getTitle() {
return title;
}