Skip to content

Instantly share code, notes, and snippets.

@felipelima94
Created February 16, 2022 14:08
Show Gist options
  • Save felipelima94/d1a04f0b90b3c6b1933522f7fc190cd7 to your computer and use it in GitHub Desktop.
Save felipelima94/d1a04f0b90b3c6b1933522f7fc190cd7 to your computer and use it in GitHub Desktop.
Spring Boot DynamoDB Config
spring:
amazon:
dynamodb:
endpoint: ${DYNAMODB_URL}
region: ${DYNAMODB_REGION}
aws:
accesskey: ${AWS_ACESS_KEY}
secretkey: ${AWS_SECRET_KEY}
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