
io.github.carousell.aws.AWSDynamoService Maven / Gradle / Ivy
package io.github.carousell.aws;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Service class to interact with AWS Dynamo DB, basically a wrapper around {@link AmazonDynamoDB}.
*/
public class AWSDynamoService {
private static final Logger LOG = LoggerFactory.getLogger(UploadAppPackage.class);
private AmazonDynamoDB awsDynamoDB;
/**
* Constructor
*
* @param awsAccessKey the AWS access key
* @param awsSecretKey the AWS secret key
* @param awsRegion the AWS region
*/
public AWSDynamoService(String awsAccessKey, String awsSecretKey, String awsRegion) {
awsDynamoDB = buildDynamoClient(awsAccessKey, awsSecretKey, awsRegion);
}
/** @return {@link AmazonDynamoDB} */
public AmazonDynamoDB getAwsDynamo() {
return awsDynamoDB;
}
private AmazonDynamoDB buildDynamoClient(
String awsAccessKey, String awsSecretKey, String awsRegion) {
LOG.debug("Building AWS Device Farm client");
LOG.debug("awsAccessKey={}", awsAccessKey);
LOG.debug("awsSecretKey={}", awsSecretKey);
LOG.debug("awsRegion={}", awsRegion);
AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
AWSCredentialsProvider awsCredentialsProvider =
new AWSStaticCredentialsProvider(awsCredentials);
AmazonDynamoDBClientBuilder awsDynamoBuilder =
AmazonDynamoDBClientBuilder.standard().withRegion(awsRegion);
awsDynamoBuilder.setCredentials(awsCredentialsProvider);
return awsDynamoBuilder.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy