Search in sources :

Example 6 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project nifi by apache.

the class AbstractDynamoDBProcessor method createClient.

/**
 * Create client using credentials provider. This is the preferred way for creating clients
 */
@Override
protected AmazonDynamoDBClient createClient(final ProcessContext context, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration config) {
    getLogger().debug("Creating client with credentials provider");
    final AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentialsProvider, config);
    return client;
}
Also used : AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)

Example 7 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project wildfly-camel by wildfly-extras.

the class DynamoDBIntegrationTest method testKeyValueOperations.

@Test
public void testKeyValueOperations() throws Exception {
    AmazonDynamoDBClient client = provider.getClient();
    Assume.assumeNotNull("AWS client not null", client);
    DynamoDBUtils.assertNoStaleTables(client, "before");
    try {
        try {
            TableDescription description = DynamoDBUtils.createTable(client, tableName);
            Assert.assertEquals("ACTIVE", description.getTableStatus());
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("ddbClientA", client);
            camelctx.addRoutes(new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    from("direct:start").to("aws-ddb://" + tableName + "?amazonDDBClient=#ddbClientA");
                }
            });
            camelctx.start();
            try {
                DynamoDBUtils.putItem(camelctx, "Book 103 Title");
                String result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Title", result);
                DynamoDBUtils.updItem(camelctx, "Book 103 Update");
                result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Update", result);
            } finally {
                camelctx.stop();
            }
        } finally {
            DynamoDBUtils.deleteTable(client, tableName);
        }
    } finally {
        DynamoDBUtils.assertNoStaleTables(client, "after");
    }
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) RouteBuilder(org.apache.camel.builder.RouteBuilder) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Test(org.junit.Test)

Example 8 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient 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)

Example 9 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project tutorials by eugenp.

the class SavePersonHandler method initDynamoDbClient.

private void initDynamoDbClient() {
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    client.setRegion(Region.getRegion(REGION));
    this.dynamoDb = new DynamoDB(client);
}
Also used : DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)

Example 10 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project archaius by Netflix.

the class DynamoDbConfigurationSourceIntegrationTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    try {
        dbClient = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain().getCredentials());
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.setProperty("com.netflix.config.dynamo.tableName", tableName);
    if (dbClient != null) {
        createTable(dbClient, tableName);
        addElements(dbClient, tableName);
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) BeforeClass(org.junit.BeforeClass)

Aggregations

AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)14 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)5 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)5 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)5 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)4 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)4 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)4 BeforeClass (org.junit.BeforeClass)4 ClientConfiguration (com.amazonaws.ClientConfiguration)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)3 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)3 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)3 SneakyThrows (lombok.SneakyThrows)3 Test (org.junit.Test)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)2 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)2 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)2 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)2