Example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient AmazonDynamoDBClient

List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient AmazonDynamoDBClient

Introduction

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

Prototype

@Deprecated
public AmazonDynamoDBClient() 

Source Link

Document

Constructs a new client to invoke service methods on DynamoDB.

Usage

From source file:drivethru.DriveThruSpeechlet.java

License:Open Source License

/**
 * Initializes the instance components if needed.
 *//*www  . j  a  va 2s .  c  o m*/
private void initializeComponents() {
    if (amazonDynamoDBClient == null) {
        amazonDynamoDBClient = new AmazonDynamoDBClient();
        driveThruManager = new DriveThruManager(amazonDynamoDBClient);
        skillContext = new SkillContext();
    }
}

From source file:dynamok.sink.DynamoDbSinkTask.java

License:Apache License

@Override
public void start(Map<String, String> props) {
    config = new ConnectorConfig(props);

    if (config.accessKeyId.value().isEmpty() || config.secretKeyId.value().isEmpty()) {
        client = new AmazonDynamoDBClient();
        log.debug("AmazonDynamoDBClient created with default credentials");
    } else {/*w w w  . ja va  2  s  . com*/
        BasicAWSCredentials awsCreds = new BasicAWSCredentials(config.accessKeyId.value(),
                config.secretKeyId.value());
        client = new AmazonDynamoDBClient(awsCreds);
        log.debug("AmazonDynamoDBClient created with AWS credentials from connector configuration");
    }

    client.configureRegion(config.region);
    remainingRetries = config.maxRetries;
}

From source file:dynamok.source.DynamoDbSourceConnector.java

License:Apache License

@Override
public void start(Map<String, String> props) {
    config = new ConnectorConfig(props);
    streamShards = new HashMap<>();

    final AmazonDynamoDBClient client;
    final AmazonDynamoDBStreamsClient streamsClient;

    if (config.accessKeyId.value().isEmpty() || config.secretKeyId.value().isEmpty()) {
        client = new AmazonDynamoDBClient();
        streamsClient = new AmazonDynamoDBStreamsClient();
        log.debug("AmazonDynamoDB clients created with default credentials");
    } else {/*from  w w  w  .j a  va2  s  .  c o m*/
        BasicAWSCredentials awsCreds = new BasicAWSCredentials(config.accessKeyId.value(),
                config.secretKeyId.value());
        client = new AmazonDynamoDBClient(awsCreds);
        streamsClient = new AmazonDynamoDBStreamsClient(awsCreds);
        log.debug("AmazonDynamoDB clients created with AWS credentials from connector configuration");
    }

    client.configureRegion(config.region);
    streamsClient.configureRegion(config.region);

    final Set<String> ignoredTables = new HashSet<>();
    final Set<String> consumeTables = new HashSet<>();

    String lastEvaluatedTableName = null;
    do {
        final ListTablesResult listResult = client.listTables(lastEvaluatedTableName);

        for (String tableName : listResult.getTableNames()) {
            if (!acceptTable(tableName)) {
                ignoredTables.add(tableName);
                continue;
            }

            final TableDescription tableDesc = client.describeTable(tableName).getTable();

            final StreamSpecification streamSpec = tableDesc.getStreamSpecification();

            if (streamSpec == null || !streamSpec.isStreamEnabled()) {
                throw new ConnectException(
                        String.format("DynamoDB table `%s` does not have streams enabled", tableName));
            }

            final String streamViewType = streamSpec.getStreamViewType();
            if (!streamViewType.equals(StreamViewType.NEW_IMAGE.name())
                    && !streamViewType.equals(StreamViewType.NEW_AND_OLD_IMAGES.name())) {
                throw new ConnectException(String.format("DynamoDB stream view type for table `%s` is %s",
                        tableName, streamViewType));
            }

            final DescribeStreamResult describeStreamResult = streamsClient
                    .describeStream(new DescribeStreamRequest().withStreamArn(tableDesc.getLatestStreamArn()));

            for (Shard shard : describeStreamResult.getStreamDescription().getShards()) {
                streamShards.put(shard, tableDesc);
            }

            consumeTables.add(tableName);
        }

        lastEvaluatedTableName = listResult.getLastEvaluatedTableName();
    } while (lastEvaluatedTableName != null);

    log.info("Tables to ignore: {}", ignoredTables);
    log.info("Tables to ingest: {}", consumeTables);

    client.shutdown();
    streamsClient.shutdown();
}

From source file:io.helixservice.feature.configuration.dynamo.DynamoConfigResourceLocator.java

License:Open Source License

private void configureDynamoConnection() {
    if (!StringUtils.isNullOrEmpty(accessKey) && !StringUtils.isNullOrEmpty(secretKey)) {
        //set the credentials as system properties
        System.setProperty("aws.accessKeyId", accessKey);
        System.setProperty("aws.secretKey", secretKey);
        LOG.info("accessKeyId and secretKey passed successfully via configuration");
    } else {//from   ww w .j av  a  2s . c om
        LOG.error("accessKeyId or secretKey not set");
    }

    client = new AmazonDynamoDBClient().withEndpoint(clientEndpoint);
    configTable = new DynamoDB(client).getTable(tableName);
}

From source file:io.klerch.alexa.state.handler.AWSDynamoStateHandler.java

License:Open Source License

/**
 * The most convenient constructor just takes the Alexa session. An AWS client for accessing DynamoDB
 * will make use of all defaults in regards to credentials and region. The credentials used in this client need permission for reading, writing and
 * removing items from a DynamoDB table and also the right to create a table. On the very first read or
 * write operation of this handler it creates a table named like your Alexa App Id.
 * The table created consist of a hash-key and a sort-key.
 * If you don't want this handler to auto-create a table provide the name of an existing table in DynamoDB
 * in another constructor./*from  w w  w  . j a v a2  s.  c  o m*/
 * @param session The Alexa session of your current skill invocation.
 */
public AWSDynamoStateHandler(final Session session) {
    this(session, new AmazonDynamoDBClient(), null, 10L, 5L);
}

From source file:io.klerch.alexa.state.handler.AWSDynamoStateHandler.java

License:Open Source License

/**
 * Takes the Alexa session and a table. An AWS client for accessing DynamoDB
 * will make use of all defaults in regards to credentials and region. The credentials used in this client need permission for reading, writing and
 * removing items from the given DynamoDB table. The table needs a string hash-key with name model-class and a string sort-key
 * of name amzn-user-id. The option of providing an existing table to this handler prevents it from checking its existence
 * which might end up with a better performance. You also don't need to provide permission of creating a DynamoDB table to
 * the credentials of the given AWS client.
 * @param session The Alexa session of your current skill invocation.
 * @param tableName An existing table accessible by the client and with string hash-key named model-class and a string sort-key named amzn-user-id.
 */// w ww  .  j ava2  s.c  o  m
public AWSDynamoStateHandler(final Session session, final String tableName) {
    this(session, new AmazonDynamoDBClient(), tableName, 10L, 5L);
}

From source file:io.klerch.alexa.state.handler.AWSDynamoStateHandlerIT.java

License:Open Source License

@AfterClass
public static void deleteTable() {
    final DeleteTableRequest deleteTableRequest = new DeleteTableRequest(tableName);
    // credentials need to be set in local environment
    // see http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html
    TableUtils.deleteTableIfExists(new AmazonDynamoDBClient(), deleteTableRequest);
}

From source file:lifecounter.LifeCounterSpeechlet.java

License:Open Source License

/**
 * Initializes the instance components if needed.
 *///  w w w . java2s.c o m
private void initializeComponents() {
    if (amazonDynamoDBClient == null) {
        amazonDynamoDBClient = new AmazonDynamoDBClient();
        scoreKeeperManager = new LifeCounterManager(amazonDynamoDBClient);
        skillContext = new LifeCounterSkillContext();
    }
}

From source file:scorekeeper.ScoreKeeperSpeechlet.java

License:Open Source License

/**
 * Initializes the instance components if needed.
 *///from w ww. j  av a2s.c om
private void initializeComponents() {
    if (amazonDynamoDBClient == null) {
        amazonDynamoDBClient = new AmazonDynamoDBClient();
        scoreKeeperManager = new ScoreKeeperManager(amazonDynamoDBClient);
        skillContext = new SkillContext();
    }
}

From source file:se.symsoft.codecamp.SmsGeneratorService.java

License:Open Source License

private HttpServer start() throws IOException {
    AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient().withRegion(Regions.EU_WEST_1);
    dynamoDB = new DynamoDBMapper(amazonDynamoDBClient);

    sqsClient = new AmazonSQSClient().withRegion(Regions.EU_WEST_1);
    String queueName = System.getenv("SQS_QUEUE_NAME");
    System.out.println("SQS_QUEUE_NAME = " + queueName);
    GetQueueUrlResult result = sqsClient.getQueueUrl(queueName);
    queueUrl = result.getQueueUrl();/* w  ww  .  j a  va  2s  .co  m*/
    SqsMessageReceiver sqsMessageReceiver = new SqsMessageReceiver(this, sqsClient, queueName);
    new Thread(sqsMessageReceiver).start();

    Metrics.startGraphiteMetricsReporter();

    URI baseUri = UriBuilder.fromUri("http://0.0.0.0/").port(8070).build();

    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, this);
    server.getServerConfiguration().addHttpHandler(
            new CLStaticHttpHandler(SmsGeneratorService.class.getClassLoader(), "web/"), "/generator-ui");
    server.start();
    return server;
}