Skip to content

HillmerCh/springboot-dynamodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Library SpringBoot-DynamoDb

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

The code

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

Dependencies (pom.xml file)

com.amazonaws::aws-java-sdk-dynamodb
io.github.boostchicken::spring-data-dynamodb

Dependencies for Testing with a Local DynamoDB (pom.xml file)

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

The DynamoDB Configuration class (org.hillmerch.library.data.config.DynamoDBConfig)

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 BookInfo entity class (org.hillmerch.library.data.model.BookInfo)

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;
}

About

SpringBoot with DynamoDB example

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published