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:aws.example.dynamodb.UpdateTable.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    UpdateTable <table> <read> <write>\n\n" + "Where:\n"
            + "    table - the table to put the item in.\n"
            + "    read  - the new read capacity of the table.\n"
            + "    write - the new write capacity of the table.\n\n" + "Example:\n"
            + "    UpdateTable HelloTable 16 10\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);/*from   www . jav  a2s  . c  o m*/
    }

    String table_name = args[0];
    Long read_capacity = Long.parseLong(args[1]);
    Long write_capacity = Long.parseLong(args[2]);

    System.out.format("Updating %s with new provisioned throughput values\n", table_name);
    System.out.format("Read capacity : %d\n", read_capacity);
    System.out.format("Write capacity : %d\n", write_capacity);

    ProvisionedThroughput table_throughput = new ProvisionedThroughput(read_capacity, write_capacity);

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        ddb.updateTable(table_name, table_throughput);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:awslabs.lab51.SolutionCode.java

License:Open Source License

@Override
public AmazonDynamoDBClient createDynamoDbClient(AWSCredentials credentials) {
    Region region = Region.getRegion(Regions.fromName(System.getProperty("REGION")));
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    client.setRegion(region);//from  ww  w .  jav a 2  s .c  o  m

    return client;
}

From source file:com.achow101.bittipaddr.server.addressServiceImpl.java

License:Open Source License

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Get the id
    String requestURI = request.getRequestURI();
    String id = requestURI.substring(requestURI.lastIndexOf("/") + 1);

    // Setup the aws dynamo db client
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    DynamoDB dynamoDB = new DynamoDB(client);

    // Setup blockcypher API
    BlockCypherContext blockCypherContext = new BlockCypherContext("v1", "btc", "main",
            "4d3109a5c07f426da9ccc2943da39244");

    // Lookup ID and get current address, increment index
    String address = "";
    Table table = dynamoDB.getTable("Bittipaddrs");
    int currAddrInx = 0;
    try {//from   w ww. java2 s . c om
        Item item = table.getItem("ID", id);
        currAddrInx = item.getInt("AddrIndex");
        int origIndx = currAddrInx;
        List<String> addresses = item.getList("Addresses");
        if (currAddrInx < addresses.size()) {
            address = addresses.get(currAddrInx);

            while (blockCypherContext.getAddressService().getAddress(address).getnTx() > 0
                    && currAddrInx < addresses.size()) {
                // Increment index and get next address
                currAddrInx++;
                address = addresses.get(currAddrInx);

                // Wait one third of a second to prevent rate limiting
                Thread.sleep(334);
            }
        } else {
            address = addresses.get(addresses.size() - 1);
        }

        // Update index if DB if it has changed
        if (currAddrInx != origIndx) {
            UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("ID", id)
                    .withUpdateExpression("set AddrIndex=:i")
                    .withValueMap(new ValueMap().withNumber(":i", currAddrInx));
            table.updateItem(updateItemSpec);
        }
    }
    // Deal with rate limiting from BlockCypher
    catch (BlockCypherException e) {
        UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("ID", id)
                .withUpdateExpression("set AddrIndex=:i")
                .withValueMap(new ValueMap().withNumber(":i", currAddrInx));
        table.updateItem(updateItemSpec);
    } catch (Exception e) {
        System.out.println("Error in getting item.");
    }

    // Send them a redirect to the bitcoin uri if redirect is set
    if (request.getParameter("redirect") != null) {
        response.sendRedirect("bitcoin:" + address);
    } else {
        // Set response content type
        response.setContentType("text/html");

        // Actual logic goes here.
        PrintWriter out = response.getWriter();
        out.println("<a href=bitcoin:" + address + ">" + address + "</a>");

    }
}

From source file:com.achow101.bittipaddr.server.bittipaddrServiceImpl.java

License:Open Source License

public String addAddresses(AddrReq req) {

    // Setup the aws dynamo db client
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("Bittipaddrs");

    // Check that the request is for editing an existing one
    if (!req.getId().equals("NEW")) {
        try {//from  w ww. ja  v  a2  s  .  c o m
            Item item = table.getItem("ID", req.getId());

            // Check the password
            if (getHash(req.getPassword()).equals(item.getString("passhash"))) {
                // If the req has been edited, update DB
                if (req.isEdited()) {
                    // Recalculate addresses if xpub is set
                    if (!req.getXpub().equals("NONE")) {
                        try {
                            // Check Xpub
                            DeterministicKey xpub = DeterministicKey.deserializeB58(req.getXpub(), params);
                            DeterministicKey external = HDKeyDerivation.deriveChildKey(xpub, 0);

                            // Derive 1000 addresses and add to req
                            String[] addrs = new String[1000];
                            for (int i = 0; i < 1000; i++) {
                                addrs[i] = HDKeyDerivation.deriveChildKey(external, i).toAddress(params)
                                        .toBase58();
                            }
                            req.setAddresses(addrs);
                        } catch (Exception e) {
                            return "<p style=\"color:red;\">Invalid xpub" + req.getXpub() + "</p>";
                        }
                    }
                    if (req.getAddresses()[0].isEmpty())
                        return "<p style=\"color:red;\">Must have at least one address</p>";

                    UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("ID", req.getId())
                            .withUpdateExpression("set AddrIndex=:i, Addresses=:a, bip32xpub=:x")
                            .withValueMap(new ValueMap().withNumber(":i", 0)
                                    .withList(":a", Arrays.asList(req.getAddresses()))
                                    .withString(":x", req.getXpub()));
                    table.updateItem(updateItemSpec);
                    return req.getHtml();
                }

                String[] addresses = new String[item.getList("Addresses").size()];
                item.getList("Addresses").toArray(addresses);
                req.setAddresses(addresses);
                req.setXpub(item.getString("bip32xpub"));

                if (req.isEditable())
                    return req.getPlain();
                else
                    return req.getHtml();
            } else
                return "<p style=\"color:red;\">Incorrect password</p>";

        } catch (Exception e) {
            return "<p style=\"color:red;\">Could not find unit</p>";
        }

    }
    // Check validity of addresses
    else if (req.getXpub().equals("NONE") && req.getAddresses().length != 0) {
        for (int i = 0; i < req.getAddresses().length; i++) {
            try {
                Address addr = Address.fromBase58(params, req.getAddresses()[i]);
            } catch (AddressFormatException e) {
                return "<p style=\"color:red;\">Invalid address" + req.getAddresses()[i] + "</p>";
            }
        }
    }
    // Check validity of xpub
    else if (!req.getXpub().equals("NONE") && req.getAddresses().length == 0) {
        try {
            // Check Xpub
            DeterministicKey xpub = DeterministicKey.deserializeB58(req.getXpub(), params);
            DeterministicKey external = HDKeyDerivation.deriveChildKey(xpub, 0);

            // Derive 1000 addresses and add to req
            String[] addrs = new String[1000];
            for (int i = 0; i < 1000; i++) {
                addrs[i] = HDKeyDerivation.deriveChildKey(external, i).toAddress(params).toBase58();
            }
            req.setAddresses(addrs);
        } catch (Exception e) {
            return "<p style=\"color:red;\">Invalid xpub" + req.getXpub() + "</p>";
        }
    }

    // Set the request ID and unique password
    req.setId(new BigInteger(40, random).toString(32));
    req.setPassword(new BigInteger(256, random).toString(32));

    // Add request to DynamoDB
    Item item = null;
    try {
        item = new Item().withPrimaryKey("ID", req.getId()).withInt("AddrIndex", 0)
                .withList("Addresses", Arrays.asList(req.getAddresses())).withString("bip32xpub", req.getXpub())
                .withString("passhash", getHash(req.getPassword()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    table.putItem(item);

    return req.getHtml();
}

From source file:com.facebook.presto.kinesis.util.KinesisTestClientManager.java

License:Apache License

public KinesisTestClientManager() {
    this.dynamoDBClient = new AmazonDynamoDBClient();
    this.amazonS3Client = new AmazonS3Client();
}

From source file:com.github.mizool.technology.aws.dynamodb.AmazonDynamoDbProducer.java

License:Apache License

@Inject
public AmazonDynamoDbProducer(Configuration configuration) {
    client = new AmazonDynamoDBClient();
    client.withRegion(configuration.getAwsRegion());
    if (configuration.getEndpoint() != null) {
        client.withEndpoint(configuration.getEndpoint());
    }/*from  w w w.j  a va 2  s.co  m*/
}

From source file:com.netflix.config.sources.AbstractDynamoDbConfigurationSource.java

License:Apache License

public AbstractDynamoDbConfigurationSource() {
    this(new AmazonDynamoDBClient());
    setEndpoint();
}

From source file:com.sdlc.healthhelp.HealthHelpSpeechlet.java

License:Open Source License

private AmazonDynamoDBClient getAmazonDynamoDBClient() {
    if (this.amazonDynamoDBClient == null) {
        this.amazonDynamoDBClient = new AmazonDynamoDBClient();
    }/*from  w w w  .  j  ava2s. c o m*/
    return this.amazonDynamoDBClient;
}

From source file:com.serverless.manager.DynamoDBManager.java

License:Open Source License

private DynamoDBManager() {

    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    client.setRegion(Region.getRegion(Regions.US_WEST_1));
    mapper = new DynamoDBMapper(client);
}

From source file:com.venu.springmvc.dao.AmazonDynamoDBDAO.java

License:Open Source License

/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration, such as the service endpoints, are performed
 * automatically. Client parameters, such as proxies, can be specified in an
 * optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.ProfilesConfigFile
 * @see com.amazonaws.ClientConfiguration
 */// www  .ja va  2  s. c  om
private static void init() throws Exception {
    /*
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (C:\\Users\\vabbu\\.aws\\credentials).
     */
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider("default").getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (C:\\Users\\vabbu\\.aws\\credentials), and is in valid format.", e);
    }
    //        dynamoDB = new AmazonDynamoDBClient(credentials);
    dynamoDB = new AmazonDynamoDBClient();
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    dynamoDB.setRegion(usWest2);
}