List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient AmazonDynamoDBClient
AmazonDynamoDBClient(AwsSyncClientParams clientParams, boolean endpointDiscoveryEnabled)
From source file:com.alertlogic.aws.analytics.poc.DeleteResources.java
License:Open Source License
public static void main(String[] args) { if (args.length != 4) { System.err.println("Usage: " + DeleteResources.class.getSimpleName() + " <application name> <stream name> <DynamoDB table name> <region>"); System.exit(1);/*from w w w. j a v a 2s . c o m*/ } String applicationName = args[0]; String streamName = args[1]; String countsTableName = args[2]; Region region = Utils.parseRegion(args[3]); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = Utils.configureUserAgentForSample(new ClientConfiguration()); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig); kinesis.setRegion(region); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); StreamUtils streamUtils = new StreamUtils(kinesis); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); LOG.info("Removing Amazon Kinesis and DynamoDB resources used by the sample application..."); streamUtils.deleteStream(streamName); // The Kinesis Client Library creates a table to manage shard leases and uses the application name for its name. dynamoDBUtils.deleteTable(applicationName); dynamoDBUtils.deleteTable(countsTableName); }
From source file:com.alertlogic.aws.kinesis.test1.StreamProcessor.java
License:Open Source License
/** * Start the Kinesis Client application. * /*from w ww . j a v a 2 s . co m*/ * @param args Expecting 4 arguments: Application name to use for the Kinesis Client Application, Stream name to * read from, DynamoDB table name to persist counts into, and the AWS region in which these resources * exist or should be created. */ public static void main(String[] args) throws UnknownHostException { if (args.length != 4) { System.err.println("Usage: " + StreamProcessor.class.getSimpleName() + " <application name> <stream name> <DynamoDB table name> <region>"); System.exit(1); } String applicationName = args[0]; String streamName = args[1]; String countsTableName = args[2]; Region region = SampleUtils.parseRegion(args[3]); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = SampleUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig); kinesis.setRegion(region); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); // Creates a stream to write to, if it doesn't exist StreamUtils streamUtils = new StreamUtils(kinesis); streamUtils.createStreamIfNotExists(streamName, 2); LOG.info(String.format("%s stream is ready for use", streamName)); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); dynamoDBUtils.createCountTableIfNotExists(countsTableName); LOG.info(String.format("%s DynamoDB table is ready for use", countsTableName)); String workerId = String.valueOf(UUID.randomUUID()); LOG.info(String.format("Using working id: %s", workerId)); KinesisClientLibConfiguration kclConfig = new KinesisClientLibConfiguration(applicationName, streamName, credentialsProvider, workerId); kclConfig.withCommonClientConfig(clientConfig); kclConfig.withRegionName(region.getName()); kclConfig.withInitialPositionInStream(InitialPositionInStream.LATEST); // Persist counts to DynamoDB DynamoDBCountPersister persister = new DynamoDBCountPersister( dynamoDBUtils.createMapperForTable(countsTableName)); IRecordProcessorFactory recordProcessor = new CountingRecordProcessorFactory<HttpReferrerPair>( HttpReferrerPair.class, persister, COMPUTE_RANGE_FOR_COUNTS_IN_MILLIS, COMPUTE_INTERVAL_IN_MILLIS); Worker worker = new Worker(recordProcessor, kclConfig); int exitCode = 0; try { worker.run(); } catch (Throwable t) { LOG.error("Caught throwable while processing data.", t); exitCode = 1; } System.exit(exitCode); }
From source file:com.alertlogic.aws.kinesis.test1.utils.DeleteSampleResources.java
License:Open Source License
public static void main(String[] args) { if (args.length != 4) { System.err.println("Usage: " + DeleteSampleResources.class.getSimpleName() + " <application name> <stream name> <DynamoDB table name> <region>"); System.exit(1);//ww w. ja va 2 s.c o m } String applicationName = args[0]; String streamName = args[1]; String countsTableName = args[2]; Region region = SampleUtils.parseRegion(args[3]); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = SampleUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig); kinesis.setRegion(region); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); StreamUtils streamUtils = new StreamUtils(kinesis); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); LOG.info("Removing Amazon Kinesis and DynamoDB resources used by the sample application..."); streamUtils.deleteStream(streamName); // The Kinesis Client Library creates a table to manage shard leases and uses the application name for its name. dynamoDBUtils.deleteTable(applicationName); dynamoDBUtils.deleteTable(countsTableName); }
From source file:com.alertlogic.aws.kinesis.test1.WebServer.java
License:Open Source License
/** * Start an embedded web server.//from ww w . java2 s .c o m * * @param args Expecting 4 arguments: Port number, File path to static content, the name of the * DynamoDB table where counts are persisted to, and the AWS region in which these resources * exist or should be created. * @throws Exception Error starting the web server. */ public static void main(String[] args) throws Exception { if (args.length != 4) { System.err.println("Usage: " + WebServer.class + " <port number> <directory for static content> <DynamoDB table name> <region>"); System.exit(1); } Server server = new Server(Integer.parseInt(args[0])); String wwwroot = args[1]; String countsTableName = args[2]; Region region = SampleUtils.parseRegion(args[3]); // Servlet context ServletContextHandler context = new ServletContextHandler( ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY); context.setContextPath("/api"); // Static resource context ResourceHandler resources = new ResourceHandler(); resources.setDirectoriesListed(false); resources.setWelcomeFiles(new String[] { "graph.html" }); resources.setResourceBase(wwwroot); // Create the servlet to handle /GetCounts AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = SampleUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); context.addServlet( new ServletHolder(new GetCountsServlet(dynamoDBUtils.createMapperForTable(countsTableName))), "/GetCounts/*"); HandlerList handlers = new HandlerList(); handlers.addHandler(context); handlers.addHandler(resources); handlers.addHandler(new DefaultHandler()); server.setHandler(handlers); server.start(); server.join(); }
From source file:com.innoq.hagmans.bachelor.TemperatureConsumer.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { if (args.length == 2) { streamName = args[0];// w w w . ja v a 2s.c o m db_name = args[1]; } // Initialize Utils KinesisClientLibConfiguration config = new KinesisClientLibConfiguration(db_name, streamName, new DefaultAWSCredentialsProviderChain(), "KinesisProducerLibSampleConsumer") .withRegionName(TemperatureProducer.REGION) .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON); Region region = RegionUtils.getRegion(TemperatureProducer.REGION); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient(credentialsProvider, new ClientConfiguration()); AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentialsProvider); client.setRegion(region); DynamoDB dynamoDB = new DynamoDB(client); amazonDynamoDB.setRegion(region); DynamoDBUtils dbUtils = new DynamoDBUtils(dynamoDB, amazonDynamoDB, client); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, new ClientConfiguration()); kinesis.setRegion(region); StreamUtils streamUtils = new StreamUtils(kinesis); try { if (!streamUtils.isActive(kinesis.describeStream(streamName))) { log.info("Stream is not active. Waiting for Stream to become active...."); streamUtils.waitForStreamToBecomeActive(streamName); } } catch (ResourceNotFoundException e) { log.info("Stream is not created right now. Waiting for stream to get created and become active...."); streamUtils.waitForStreamToBecomeActive(streamName); } dbUtils.deleteTable(db_name); dbUtils.createTemperatureTableIfNotExists(tableName); Thread.sleep(1000); final TemperatureConsumer consumer = new TemperatureConsumer(); new Worker.Builder().recordProcessorFactory(consumer).config(config).build().run(); }
From source file:com.intuit.tank.persistence.databases.AmazonDynamoDatabaseDocApi.java
License:Open Source License
/** * /*w w w . j a va 2 s . com*/ * @param dynamoDb */ public AmazonDynamoDatabaseDocApi() { CloudCredentials creds = new TankConfig().getVmManagerConfig().getCloudCredentials(CloudProvider.amazon); if (creds != null && StringUtils.isNotBlank(creds.getKeyId())) { AWSCredentials credentials = new BasicAWSCredentials(creds.getKeyId(), creds.getKey()); this.dynamoDb = new AmazonDynamoDBClient(credentials, new ClientConfiguration()); } else { this.dynamoDb = new AmazonDynamoDBClient(new ClientConfiguration()); } }
From source file:com.kinesis.datavis.utils.DeleteSampleResources.java
License:Open Source License
public static void main(String[] args) { if (args.length != 4) { System.err.println("Usage: " + DeleteSampleResources.class.getSimpleName() + " <application name> <stream name> <DynamoDB table name> <region>"); System.exit(1);/* ww w . j a v a2 s . c o m*/ } String applicationName = args[0]; String streamName = args[1]; String countsTableName = args[2]; Region region = AppUtils.parseRegion(args[3]); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = AppUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig); kinesis.setRegion(region); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); StreamUtils streamUtils = new StreamUtils(kinesis); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); LOG.info("Removing Amazon Kinesis and DynamoDB resources used by the sample application..."); streamUtils.deleteStream(streamName); // The Kinesis Client Library creates a table to manage shard leases and uses the application name for its name. dynamoDBUtils.deleteTable(applicationName); dynamoDBUtils.deleteTable(countsTableName); }
From source file:com.kitac.kinesissamples.consumer.communication.DynamoDBManager.java
License:Open Source License
private DynamoDBManager() { config = new ClientConfiguration(); /* TODO: ClientConfiguration setting code is here. */ AmazonDynamoDBClient client = new AmazonDynamoDBClient( // For use IAM role, specify DefaultAWSCredentialsProviderChain instance. new DefaultAWSCredentialsProviderChain(), config); client.setRegion(Regions.AP_NORTHEAST_1); dynamoDBConnection = new DynamoDB(client); }
From source file:com.netflix.config.sources.AbstractDynamoDbConfigurationSource.java
License:Apache License
public AbstractDynamoDbConfigurationSource(AWSCredentials credentials, ClientConfiguration clientConfiguration) { this(new AmazonDynamoDBClient(credentials, clientConfiguration)); setEndpoint();//from w w w .j a v a 2 s. c om }
From source file:com.netflix.config.sources.AbstractDynamoDbConfigurationSource.java
License:Apache License
public AbstractDynamoDbConfigurationSource(AWSCredentialsProvider credentialsProvider, ClientConfiguration clientConfiguration) { this(new AmazonDynamoDBClient(credentialsProvider, clientConfiguration)); setEndpoint();//from w w w . j a va 2 s .co m }