Created
February 16, 2022 14:08
-
-
Save felipelima94/d1a04f0b90b3c6b1933522f7fc190cd7 to your computer and use it in GitHub Desktop.
Spring Boot DynamoDB Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring: | |
amazon: | |
dynamodb: | |
endpoint: ${DYNAMODB_URL} | |
region: ${DYNAMODB_REGION} | |
aws: | |
accesskey: ${AWS_ACESS_KEY} | |
secretkey: ${AWS_SECRET_KEY} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.solinftec.SREClientControlRegistration.utils; | |
import com.amazonaws.auth.AWSStaticCredentialsProvider; | |
import com.amazonaws.auth.BasicAWSCredentials; | |
import com.amazonaws.client.builder.AwsClientBuilder; | |
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; | |
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; | |
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
public class DynamoDBConfig { | |
@Value("${spring.amazon.dynamodb.endpoint}") | |
private String amazonDynamoDBEndpoint; | |
@Value("${spring.amazon.aws.accesskey}") | |
private String amazonAWSAccessKey; | |
@Value("${spring.amazon.aws.secretkey}") | |
private String amazonAWSSecretKey; | |
@Value("${spring.amazon.dynamodb.region") | |
private String region; | |
@Bean | |
public DynamoDBMapper dynamoDBMapper() { | |
return new DynamoDBMapper(buildAmazonDynamoDB()); | |
} | |
private AmazonDynamoDB buildAmazonDynamoDB() { | |
return AmazonDynamoDBClientBuilder | |
.standard() | |
.withEndpointConfiguration( | |
new AwsClientBuilder.EndpointConfiguration(amazonDynamoDBEndpoint,region)) | |
.withCredentials(new AWSStaticCredentialsProvider( | |
new BasicAWSCredentials(amazonAWSAccessKey,amazonAWSSecretKey))) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment