Search in sources :

Example 1 with AmazonDynamoDB

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"));
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) PollResult(com.netflix.config.PollResult) Test(org.junit.Test)

Example 2 with AmazonDynamoDB

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;
}
Also used : AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 3 with AmazonDynamoDB

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;
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 4 with AmazonDynamoDB

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());
}
Also used : ProductInfo(com.baeldung.spring.data.dynamodb.model.ProductInfo) ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) Before(org.junit.Before)

Example 5 with AmazonDynamoDB

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);
}
Also used : ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) BeforeClass(org.junit.BeforeClass) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) URISyntaxException(java.net.URISyntaxException) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Assert.assertThat(org.junit.Assert.assertThat) ProductInfo(com.baeldung.dynamodb.entity.ProductInfo) Is.is(org.hamcrest.core.Is.is) LocalDbCreationRule(com.baeldung.dynamodb.rule.LocalDbCreationRule) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Before(org.junit.Before) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Properties(java.util.Properties) Files(java.nio.file.Files) Test(org.junit.Test) IOException(java.io.IOException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) List(java.util.List) ProductInfoRepository(com.baeldung.dynamodb.repository.ProductInfoRepository) Paths(java.nio.file.Paths) DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper) Optional(java.util.Optional) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) InputStream(java.io.InputStream) DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) Properties(java.util.Properties) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) BeforeClass(org.junit.BeforeClass)

Aggregations

AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)70 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)16 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)14 Test (org.junit.Test)13 Table (com.amazonaws.services.dynamodbv2.document.Table)12 IOException (java.io.IOException)12 AmazonServiceException (com.amazonaws.AmazonServiceException)11 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)11 HashMap (java.util.HashMap)11 AmazonClientException (com.amazonaws.AmazonClientException)10 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)10 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)9 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)9 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)8 ToString (lombok.ToString)7 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)6 ArrayList (java.util.ArrayList)6 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)5 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)5 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)5