in src/main/java/com/awsblog/queueing/sdk/QueueSdkClient.java [88:147]
private QueueSdkClient initialize() {
// for this AWS Blog Post we are doing string comparison using English locale
Locale.setDefault(Locale.ENGLISH);
String accessKey = System.getenv("AWS_ACCESS_KEY_ID");
String secretKey = System.getenv("AWS_SECRET_ACCESS_KEY");
if (Utils.checkIfNotNullAndNotEmptyString(accessKey) && Utils.checkIfNotNullAndNotEmptyString(secretKey)) {
if (Utils.checkIfNullOrEmptyString(accessKey))
accessKey = System.getenv("AWS_ACCESS_KEY_ID");
if (Utils.checkIfNullOrEmptyString(secretKey))
secretKey = System.getenv("AWS_SECRET_ACCESS_KEY");
this.credentials = new BasicAWSCredentials(accessKey, secretKey);
}
else if (Utils.checkIfNotNullAndNotEmptyString(this.awsCredentialsProfileName)) {
this.credentials = new ProfileCredentialsProvider(this.awsCredentialsProfileName).getCredentials();
}
AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard();
if (!Utils.checkIfNullObject(this.credentials)) builder.withCredentials(new AWSStaticCredentialsProvider(this.credentials));
if (!Utils.checkIfNullObject(this.awsRegion)) builder.withRegion(this.awsRegion);
this.dynamoDB = builder
.withClientConfiguration(new ClientConfiguration().withMaxConnections(100).withConnectionTimeout(30000).withRetryPolicy(RETRY_POLICY)).build();
// get the configuration information
this.config = Configuration.loadConfiguration();
this.actualTableName = this.config.getTablesMap().get(this.logicalTableName).getTableName();
Utils.throwIfNullOrEmptyString(this.actualTableName, "Actual DynamoDB table name is not found!");
this.key = this.config.getTablesMap().get(this.logicalTableName).getPartitionKey();
AmazonS3ClientBuilder s3builder = AmazonS3ClientBuilder.standard();
if (!Utils.checkIfNullObject(this.credentials)) s3builder.withCredentials(new AWSStaticCredentialsProvider(this.credentials));
if (!Utils.checkIfNullObject(this.awsRegion)) s3builder.withRegion(this.awsRegion);
this.s3 = s3builder.build();
AmazonSNSClientBuilder snsBuilder = AmazonSNSClientBuilder.standard();
if (!Utils.checkIfNullObject(this.credentials)) snsBuilder.withCredentials(new AWSStaticCredentialsProvider(this.credentials));
if (!Utils.checkIfNullObject(this.awsRegion)) snsBuilder.withRegion(this.awsRegion);
this.sns = snsBuilder.build();
DynamoDBMapperConfig mapperConfig = DynamoDBMapperConfig.builder()
.withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.CLOBBER)
.withConsistentReads(DynamoDBMapperConfig.ConsistentReads.CONSISTENT)
//.withConsistentReads(DynamoDBMapperConfig.ConsistentReads.EVENTUAL)
.withTableNameOverride(new DynamoDBMapperConfig.TableNameOverride(this.actualTableName))
.withPaginationLoadingStrategy(DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING)
.build();
this.dbMapper = new DynamoDBMapper(this.dynamoDB, mapperConfig);
return this;
}