Search in sources :

Example 16 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project amos-ss17-alexa by c-i-ber.

the class DynamoDbClient method getAmazonDynamoDBClient.

public static AmazonDynamoDBClient getAmazonDynamoDBClient() {
    BasicAWSCredentials credentials = new BasicAWSCredentials("AKIAIUOLL3674W3T67IQ", "X4KiAVCPab5aiW0c/93y7PnABVsPlj6YYqmfSkng");
    dynamoDB = new AmazonDynamoDBClient(credentials);
    dynamoDB.setEndpoint("http://dynamodb.us-east-1.amazonaws.com");
    return dynamoDB;
}
Also used : AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 17 with AmazonDynamoDBClient

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

the class DynamoDBUtils method createDynamoDBClient.

// Attach Policy: AmazonDynamoDBFullAccess
public static AmazonDynamoDBClient createDynamoDBClient() {
    BasicCredentialsProvider credentials = BasicCredentialsProvider.standard();
    AmazonDynamoDBClient client = !credentials.isValid() ? null : (AmazonDynamoDBClient) AmazonDynamoDBClientBuilder.standard().withCredentials(credentials).withRegion("eu-west-1").build();
    return client;
}
Also used : AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)

Example 18 with AmazonDynamoDBClient

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

the class DynamoDBStreamsIntegrationTest method testKeyValueOperations.

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

                @Override
                public void configure() throws Exception {
                    from("direct:start").to("aws-ddb://" + tableName + "?amazonDDBClient=#ddbClientB");
                    from("aws-ddbstream://" + tableName + "?amazonDynamoDbStreamsClient=#dbsClientB").to("seda:end");
                }
            });
            PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
            pollingConsumer.start();
            camelctx.start();
            try {
                DynamoDBUtils.putItem(camelctx, "Book 103 Title");
                String result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Title", result);
                Exchange exchange = pollingConsumer.receive(3000);
                Assert.assertNull(exchange);
                DynamoDBUtils.updItem(camelctx, "Book 103 Update");
                result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Update", result);
                exchange = pollingConsumer.receive(3000);
                StreamRecord record = exchange.getIn().getBody(Record.class).getDynamodb();
                Map<String, AttributeValue> oldImage = record.getOldImage();
                Map<String, AttributeValue> newImage = record.getNewImage();
                Assert.assertEquals("Book 103 Title", oldImage.get("Title").getS());
                Assert.assertEquals("Book 103 Update", newImage.get("Title").getS());
            } finally {
                camelctx.stop();
            }
        } finally {
            DynamoDBUtils.deleteTable(ddbClient, tableName);
        }
    } finally {
        DynamoDBUtils.assertNoStaleTables(ddbClient, "after");
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) StreamRecord(com.amazonaws.services.dynamodbv2.model.StreamRecord) RouteBuilder(org.apache.camel.builder.RouteBuilder) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Exchange(org.apache.camel.Exchange) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) StreamRecord(com.amazonaws.services.dynamodbv2.model.StreamRecord) Record(com.amazonaws.services.dynamodbv2.model.Record) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

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