Example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDB setRegion

List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDB setRegion

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDB setRegion.

Prototype

@Deprecated
void setRegion(Region region);

Source Link

Document

An alternative to AmazonDynamoDB#setEndpoint(String) , sets the regional endpoint for this client's service calls.

Usage

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  .  ja v  a2 s. com
    }

    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   ww w  .j  a  v a2  s . c  o  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);// www. j  ava 2s .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   w w w.  j av a 2 s .c om*/
 * 
 * @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.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.DbTableDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//from  w w  w  .j av  a  2  s  .  co  m

    try {

        AmazonDynamoDB client = new AmazonDynamoDBClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeTableRequest request = new DescribeTableRequest();
        request.setTableName(detailRequest.getResourceName());

        DescribeTableResult result = client.describeTable(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving DynamoDb details from AWS", e);
    }

    return response;
}

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];//  www . j  a  va 2s  .co  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.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);// w ww.  j  a  va  2s .co  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.raoul.walkfoframe.web.DynamoDBManager.java

License:Open Source License

public static ArrayList<WOFPushNotification> getWofPushNotifications(int lastNotificationId)
        throws UnknownHostException {
    BasicAWSCredentials c = new BasicAWSCredentials("AKIAJRYXOB72QJQU3MQQ",
            "FOQ6TDEhxTqvZb6hb+5db1OQFd4nikDRh2tuGqy1");
    AmazonDynamoDB clientManager = new AmazonDynamoDBClient(c);
    clientManager.setRegion(Region.getRegion(Regions.US_WEST_2));

    AmazonDynamoDB ddb = clientManager;//  w ww .j av  a2  s . c o m
    DynamoDBMapper mapper = new DynamoDBMapper(ddb);
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();

    scanExpression.addFilterCondition("ID",
            new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
                    .withAttributeValueList(new AttributeValue().withN(lastNotificationId + "")));
    try {
        PaginatedScanList<WOFPushNotification> result = mapper.scan(WOFPushNotification.class, scanExpression);

        ArrayList<WOFPushNotification> resultList = new ArrayList<WOFPushNotification>();
        for (WOFPushNotification up : result) {
            resultList.add(up);
        }

        Log.e("Push notification result list", resultList.size() + "");

        return resultList;

    } catch (AmazonServiceException ex) {
        //HWOFameApplication.clientManager.wipeCredentialsOnAuthError(ex);
    }

    return null;
}

From source file:eu.roschi.obdkinesis.HttpReferrerCounterApplication.java

License:Open Source License

/**
 * Start the Kinesis Client application.
 * // www .j a va 2s  . c o  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 != 2) {
        System.err.println("Using default values");
        COMPUTE_RANGE_FOR_COUNTS_IN_MILLIS = 30000;
        COMPUTE_INTERVAL_IN_MILLIS = 2000;
    } else {
        COMPUTE_RANGE_FOR_COUNTS_IN_MILLIS = Integer.parseInt(args[0]);
        COMPUTE_INTERVAL_IN_MILLIS = Integer.parseInt(args[1]);
        System.err.println(
                "Using values " + Integer.parseInt(args[0]) + " width " + Integer.parseInt(args[1]) + " rate");
    }
    String applicationName = "obd_kinesis";
    String streamName = "obd_input_stream";
    String countsTableName = "obd_kinesis_count";
    Region region = SampleUtils.parseRegion("us-west-2");

    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:eu.roschi.obdkinesis.WebServer.java

License:Open Source License

/**
 * Start an embedded web server./*from   www .j  ava2  s.c om*/
 * 
 * @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 != 1) {
        System.err.println("Usage: " + WebServer.class + " <directory for static content>");
        System.exit(1);
    }
    Server server = new Server(8080);
    String wwwroot = args[0];
    String countsTableName = "obd_kinesis_count";
    Region region = SampleUtils.parseRegion("us-west-2");

    // 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();
}