List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClientBuilder standard
public static AmazonDynamoDBClientBuilder standard()
From source file:amazonsensors.LambdaAmazonSensor.java
@Override public String handleRequest(AmazonSensor sensor, Context cntxt) { AmazonDynamoDB amazonDDB = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_WEST_2).build(); Map<String, AttributeValue> item = new HashMap(); item.put(SENSOR_FIELD, new AttributeValue(sensor.getSensorID())); item.put(TEMPERATURE_FIELD, new AttributeValue(sensor.getTemperature())); amazonDDB.putItem(TABLE_NAME, item); return sensor.toString(); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java
License:Open Source License
public DynamoDbDelegate(final String endpoint, final String region, final AWSCredentialsProvider provider, final ClientConfiguration clientConfig, final Configuration titanConfig, final Map<String, RateLimiter> readRateLimit, final Map<String, RateLimiter> writeRateLimit, final long maxRetries, final long retryMillis, final String prefix, final String metricsPrefix, final RateLimiter controlPlaneRateLimiter) { if (prefix == null) { throw new IllegalArgumentException("prefix must be set"); }// w w w . j a v a 2s .co m if (metricsPrefix == null || metricsPrefix.isEmpty()) { throw new IllegalArgumentException("metrics-prefix may not be null or empty"); } this.metricsPrefix = metricsPrefix; executorGaugeName = String.format("%s.%s_executor-queue-size", this.metricsPrefix, prefix); clientThreadPool = getPoolFromNs(titanConfig); if (!MetricManager.INSTANCE.getRegistry().getNames().contains(executorGaugeName)) { MetricManager.INSTANCE.getRegistry().register(executorGaugeName, (Gauge<Integer>) () -> clientThreadPool.getQueue().size()); } client = AmazonDynamoDBClientBuilder.standard().withCredentials(provider) .withClientConfiguration(clientConfig) .withEndpointConfiguration(getEndpointConfiguration(Optional.ofNullable(endpoint), region)).build(); this.readRateLimit = readRateLimit; this.writeRateLimit = writeRateLimit; this.controlPlaneRateLimiter = controlPlaneRateLimiter; this.maxConcurrentUsers = titanConfig.get(Constants.DYNAMODB_CLIENT_EXECUTOR_MAX_CONCURRENT_OPERATIONS); this.maxRetries = maxRetries; this.retryMillis = retryMillis; if (maxConcurrentUsers < 1) { throw new IllegalArgumentException("need at least one user otherwise wont make progress on scan"); } this.listTablesApiName = String.format("%s_ListTables", prefix); }
From source file:com.euclidespaim.dynamodb.CreateTableFunction.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration("https://dynamodb.us-east-1.amazonaws.com", "us-east-1")) .build();//from w w w .j a v a 2s. co m DynamoDB dynamoDB = new DynamoDB(client); String tableName = "Movies"; try { System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("year", KeyType.HASH), // Partition // key new KeySchemaElement("title", KeyType.RANGE)), // Sort key Arrays.asList(new AttributeDefinition("year", ScalarAttributeType.N), new AttributeDefinition("title", ScalarAttributeType.S)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:com.iluwatar.serverless.baas.api.AbstractDynamoDbHandler.java
License:Open Source License
private void initAmazonDynamoDb() { AmazonDynamoDB amazonDynamoDb = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_EAST_1) .build();/* ww w.ja va 2 s .com*/ this.dynamoDbMapper = new DynamoDBMapper(amazonDynamoDb); }
From source file:com.nodestone.ksum.RecordProcessor.java
License:Open Source License
/** * Initialize DB connection to DynamoDB//w w w .j a va 2s .com */ private void initDBConnection() { AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard() .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(DB_ENDPOINT, DB_REGION)) .build(); this.dynamoDB = new DynamoDB(client); this.dbTable = dynamoDB.getTable(DB_TABLE); }
From source file:com.yahoo.athenz.zts.cert.impl.DynamoDBCertRecordStoreFactory.java
License:Apache License
AmazonDynamoDB getDynamoDBClient() {
return AmazonDynamoDBClientBuilder.standard().build();
}
From source file:kinesisadaptersample.StreamsAdapterDemo.java
License:Open Source License
/** * @param args/*from ww w .j a va 2s . com*/ */ public static void main(String[] args) throws Exception { System.out.println("Starting demo..."); String srcTable = tablePrefix + "-src"; String destTable = tablePrefix + "-dest"; streamsCredentials = new ProfileCredentialsProvider(); dynamoDBCredentials = new ProfileCredentialsProvider(); recordProcessorFactory = new StreamsRecordProcessorFactory(destTable); adapterClient = new AmazonDynamoDBStreamsAdapterClient(streamsCredentials); adapterClient.setRegion(Region.getRegion(Regions.EU_WEST_1)); dynamoDBClient = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.EU_WEST_1).build(); cloudWatchClient = AmazonCloudWatchClientBuilder.standard().withRegion(Regions.EU_WEST_1).build(); setUpTables(); workerConfig = new KinesisClientLibConfiguration("streams-adapter-demo", streamArn, streamsCredentials, "streams-demo-worker").withMaxRecords(1000).withIdleTimeBetweenReadsInMillis(500) .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON); System.out.println("Creating worker for stream: " + streamArn); worker = new Worker(recordProcessorFactory, workerConfig, adapterClient, dynamoDBClient, cloudWatchClient); System.out.println("Starting worker..."); Thread t = new Thread(worker); t.start(); Thread.sleep(25000); worker.shutdown(); t.join(); if (StreamsAdapterDemoHelper.scanTable(dynamoDBClient, srcTable).getItems() .equals(StreamsAdapterDemoHelper.scanTable(dynamoDBClient, destTable).getItems())) { System.out.println("Scan result is equal."); } else { System.out.println("Tables are different!"); } System.out.println("Done."); cleanupAndExit(0); }
From source file:kinesisadaptersample.StreamsRecordProcessorFactory.java
License:Open Source License
@Override public IRecordProcessor createProcessor() { AmazonDynamoDB dynamoDBClient = AmazonDynamoDBClientBuilder.standard().build(); return new StreamsRecordProcessor(dynamoDBClient, tableName); }
From source file:mx.iteso.desi.cloud.keyvalue.DynamoDBStorage.java
License:Apache License
public DynamoDBStorage(String dbName) { BasicAWSCredentials cred = new BasicAWSCredentials(Config.accessKeyID, Config.secretAccessKey); if (Config.DynamoDbClientType == Config.DYNAMODBCLIENTTYPE.Local) { client = new AmazonDynamoDBClient(cred); client.setRegion(Region.getRegion(Config.amazonRegion)); client.setEndpoint("http://localhost:8000"); } else {/*from ww w . j a v a 2 s.com*/ client = AmazonDynamoDBClientBuilder.standard().withRegion(Config.amazonRegion) .withCredentials(new AWSStaticCredentialsProvider(cred)).build(); } docClient = new DynamoDB(client); this.dbName = dbName; // Create a table CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(dbName) .withKeySchema(new KeySchemaElement().withAttributeName("keyword").withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName("inx").withKeyType(KeyType.RANGE)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName("keyword") .withAttributeType(ScalarAttributeType.S), new AttributeDefinition().withAttributeName("inx").withAttributeType(ScalarAttributeType.N)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); // Create table if it does not exist yet TableUtils.createTableIfNotExists(client, createTableRequest); // Wait for the table to move into Active state try { TableUtils.waitUntilActive(client, dbName); } catch (Exception e) { // Do nothing... yet } //requestItems.put(dbName, requestList); }
From source file:mx.iteso.msc.asn.temperaturecollector.TemperatureCollector.java
License:Apache License
@Override public JSONObject handleRequest(Temperature t, Context c) { JSONObject json = new JSONObject(); AmazonDynamoDB db = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_EAST_1).build(); String tableName = "BitacoraLectura"; c.getLogger()/*from ww w. j ava 2s.c om*/ .log(("Temperature " + t.getTemperature() + " received from sensor " + t.getSensorId() + "\n")); Map<String, AttributeValue> item = new HashMap<>(); item.put("SensorId", new AttributeValue(t.getSensorId())); item.put("Temperature", new AttributeValue(Float.toString(t.getTemperature()))); db.putItem(tableName, item); json.put("result", "Ok"); c.getLogger().log(("Record added\n")); return json; }