use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project aws-doc-sdk-examples by awsdocs.
the class MoviesItemOps04 method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
int year = 2015;
String title = "The Big New Movie";
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("year", year, "title", title).withUpdateExpression("set info.rating = info.rating + :val").withValueMap(new ValueMap().withNumber(":val", 1)).withReturnValues(ReturnValue.UPDATED_NEW);
try {
System.out.println("Incrementing an atomic counter...");
UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
System.out.println("UpdateItem succeeded:\n" + outcome.getItem().toJSONPretty());
} catch (Exception e) {
System.err.println("Unable to update item: " + year + " " + title);
System.err.println(e.getMessage());
}
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBLocalFixture method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB dynamodb = null;
try {
// Create an in-memory and in-process instance of DynamoDB Local
// that skips HTTP
dynamodb = DynamoDBEmbedded.create();
// use the DynamoDB API with DynamoDBEmbedded
listTables(dynamodb.listTables(), "DynamoDB Embedded");
} finally {
// Shutdown the thread pools in DynamoDB Local / Embedded
if (dynamodb != null) {
dynamodb.shutdown();
}
}
// Create an in-memory and in-process instance of DynamoDB Local that
// runs over HTTP
final String[] localArgs = { "-inMemory" };
DynamoDBProxyServer server = null;
try {
server = ServerRunner.createServerFromCommandLineArgs(localArgs);
server.start();
dynamodb = new AmazonDynamoDBClient();
dynamodb.setEndpoint("http://localhost:8000");
// use the DynamoDB API over HTTP
listTables(dynamodb.listTables(), "DynamoDB Local over HTTP");
} finally {
// Stop the DynamoDB Local endpoint
if (server != null) {
server.stop();
}
}
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project athenz by yahoo.
the class DynamoDBSSHRecordStoreFactoryTest method testGetDynamoDBClient.
@Test
public void testGetDynamoDBClient() {
System.setProperty(ZTS_PROP_DYNAMODB_KEY_PATH, "test.keypath");
System.setProperty(ZTS_PROP_DYNAMODB_CERT_PATH, "test.certpath");
System.setProperty(ZTS_PROP_DYNAMODB_DOMAIN, "test.domain");
System.setProperty(ZTS_PROP_DYNAMODB_REGION, "test.region");
System.setProperty(ZTS_PROP_DYNAMODB_ROLE, "test.role");
System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE, "test.truststore");
System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_PASSWORD, "test.truststore.password");
System.setProperty(ZTS_PROP_DYNAMODB_ZTS_URL, "test.ztsurl");
System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_APPNAME, "test.appname");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
when(keyStore.getApplicationSecret(Mockito.eq("test.appname"), Mockito.eq("test.truststore.password"))).thenReturn("decryptedPassword");
DynamoDBSSHRecordStoreFactory factory = new DynamoDBSSHRecordStoreFactory();
ZTSClientNotificationSenderImpl ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSenderImpl.class);
PrivateKeyStore privateKeyStore = Mockito.mock(PrivateKeyStore.class);
AmazonDynamoDB dynamoDBClient = factory.getDynamoDBClient(ztsClientNotificationSender, privateKeyStore);
assertNotNull(dynamoDBClient);
System.clearProperty(ZTS_PROP_DYNAMODB_KEY_PATH);
System.clearProperty(ZTS_PROP_DYNAMODB_CERT_PATH);
System.clearProperty(ZTS_PROP_DYNAMODB_DOMAIN);
System.clearProperty(ZTS_PROP_DYNAMODB_REGION);
System.clearProperty(ZTS_PROP_DYNAMODB_ROLE);
System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE);
System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_PASSWORD);
System.clearProperty(ZTS_PROP_DYNAMODB_ZTS_URL);
System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_APPNAME);
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project athenz by yahoo.
the class DynamoDBCertRecordStoreFactoryTest method testGetDynamoDBClient.
@Test
public void testGetDynamoDBClient() {
System.setProperty(ZTS_PROP_DYNAMODB_KEY_PATH, "test.keypath");
System.setProperty(ZTS_PROP_DYNAMODB_CERT_PATH, "test.certpath");
System.setProperty(ZTS_PROP_DYNAMODB_DOMAIN, "test.domain");
System.setProperty(ZTS_PROP_DYNAMODB_REGION, "test.region");
System.setProperty(ZTS_PROP_DYNAMODB_ROLE, "test.role");
System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE, "test.truststore");
System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_PASSWORD, "test.truststore.password");
System.setProperty(ZTS_PROP_DYNAMODB_ZTS_URL, "test.ztsurl");
System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_APPNAME, "test.appname");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
when(keyStore.getApplicationSecret(Mockito.eq("test.appname"), Mockito.eq("test.truststore.password"))).thenReturn("decryptedPassword");
DynamoDBCertRecordStoreFactory factory = new DynamoDBCertRecordStoreFactory();
ZTSClientNotificationSenderImpl ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSenderImpl.class);
PrivateKeyStore privateKeyStore = Mockito.mock(PrivateKeyStore.class);
AmazonDynamoDB dynamoDBClient = factory.getDynamoDBClient(ztsClientNotificationSender, privateKeyStore);
assertNotNull(dynamoDBClient);
System.clearProperty(ZTS_PROP_DYNAMODB_KEY_PATH);
System.clearProperty(ZTS_PROP_DYNAMODB_CERT_PATH);
System.clearProperty(ZTS_PROP_DYNAMODB_DOMAIN);
System.clearProperty(ZTS_PROP_DYNAMODB_REGION);
System.clearProperty(ZTS_PROP_DYNAMODB_ROLE);
System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE);
System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_PASSWORD);
System.clearProperty(ZTS_PROP_DYNAMODB_ZTS_URL);
System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_APPNAME);
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project athenz by yahoo.
the class DynamoDBClientFetcherImplTest method testGetClientWithDefaultRegion.
@Test
public void testGetClientWithDefaultRegion() {
DynamoDBClientFetcher dynamoDBClientFetcher = new DynamoDBClientFetcherImpl("testRegion");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
ZTSClientNotificationSender ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSender.class);
AmazonDynamoDB dynamoDBClient = dynamoDBClientFetcher.getDynamoDBClient(ztsClientNotificationSender, keyStore).getAmazonDynamoDB();
assertNotNull(dynamoDBClient);
}
Aggregations