use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project archaius by Netflix.
the class DynamoDbConfigurationSourceTest method testPoll.
@Test
public void testPoll() throws Exception {
AmazonDynamoDB mockBasicDbClient = mock(AmazonDynamoDB.class);
when(mockBasicDbClient.scan(any(ScanRequest.class))).thenReturn(DynamoDbMocks.basicScanResult1);
DynamoDbConfigurationSource testConfigSource = new DynamoDbConfigurationSource(mockBasicDbClient);
PollResult result = testConfigSource.poll(false, null);
assertEquals(3, result.getComplete().size());
assertEquals("bar", result.getComplete().get("foo"));
assertEquals("goo", result.getComplete().get("goo"));
assertEquals("who", result.getComplete().get("boo"));
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project camel by apache.
the class DdbEndpoint method createDdbClient.
AmazonDynamoDB createDdbClient() {
AmazonDynamoDB client = null;
ClientConfiguration clientConfiguration = null;
boolean isClientConfigFound = false;
if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost(configuration.getProxyHost());
clientConfiguration.setProxyPort(configuration.getProxyPort());
isClientConfigFound = true;
}
if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
if (isClientConfigFound) {
client = new AmazonDynamoDBClient(credentials, clientConfiguration);
} else {
client = new AmazonDynamoDBClient(credentials);
}
} else {
if (isClientConfigFound) {
client = new AmazonDynamoDBClient();
} else {
client = new AmazonDynamoDBClient(clientConfiguration);
}
}
return client;
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project cas by apereo.
the class DynamoDbCloudConfigBootstrapConfiguration method getAmazonDynamoDbClient.
private static AmazonDynamoDB getAmazonDynamoDbClient(final Environment environment) {
final ClientConfiguration cfg = new ClientConfiguration();
try {
final String localAddress = getSetting(environment, "localAddress");
if (StringUtils.isNotBlank(localAddress)) {
cfg.setLocalAddress(InetAddress.getByName(localAddress));
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
final String key = getSetting(environment, "credentialAccessKey");
final String secret = getSetting(environment, "credentialSecretKey");
final AWSCredentials credentials = new BasicAWSCredentials(key, secret);
String region = getSetting(environment, "region");
if (StringUtils.isBlank(region)) {
region = Regions.getCurrentRegion().getName();
}
String regionOverride = getSetting(environment, "regionOverride");
if (StringUtils.isNotBlank(regionOverride)) {
regionOverride = Regions.getCurrentRegion().getName();
}
final String endpoint = getSetting(environment, "endpoint");
final AmazonDynamoDB client = AmazonDynamoDBClient.builder().withCredentials(new AWSStaticCredentialsProvider(credentials)).withClientConfiguration(cfg).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, regionOverride)).withRegion(region).build();
return client;
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project tutorials by eugenp.
the class ProductInfoRepositoryIntegrationTest method setup.
@Before
public void setup() throws Exception {
try {
dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB);
CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class);
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
amazonDynamoDB.createTable(tableRequest);
} catch (ResourceInUseException e) {
// Do nothing, table already created
}
// TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project tutorials by eugenp.
the class ProductInfoRepositoryIntegrationTest method setupClass.
@BeforeClass
public static void setupClass() {
Properties testProperties = loadFromFileInClasspath("test.properties").filter(properties -> !isEmpty(properties.getProperty(AWS_ACCESSKEY))).filter(properties -> !isEmpty(properties.getProperty(AWS_SECRETKEY))).filter(properties -> !isEmpty(properties.getProperty(DYNAMODB_ENDPOINT))).orElseThrow(() -> new RuntimeException("Unable to get all of the required test property values"));
String amazonAWSAccessKey = testProperties.getProperty(AWS_ACCESSKEY);
String amazonAWSSecretKey = testProperties.getProperty(AWS_SECRETKEY);
String amazonDynamoDBEndpoint = testProperties.getProperty(DYNAMODB_ENDPOINT);
amazonDynamoDB = new AmazonDynamoDBClient(new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey));
amazonDynamoDB.setEndpoint(amazonDynamoDBEndpoint);
dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB);
}
Aggregations