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

AmazonDynamoDBClient(AwsSyncClientParams clientParams) 

Source Link

Document

Constructs a new client to invoke service methods on DynamoDB using the specified parameters.

Usage

From source file:NYSELoad.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
 *//*from   w  w w .jav a2  s.c  o m*/
private static void init() throws Exception {
    /*
     * The ProfileCredentialsProvider will return your [default] credential
     * profile by reading from the credentials file located at
     * (/Users/usdgadiraj/.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 (/Users/usdgadiraj/.aws/credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region region = Region.getRegion(Regions.US_EAST_1);
    dynamoDB.setRegion(region);
    dynamoDB.setEndpoint("http://dynamo.itversity.com:8000");
}

From source file:AddUserPassword.java

License:Open Source License

public static void main(String[] args) throws Exception {

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());

    DynamoDB dynamoDB = new DynamoDB(client);

    Table table = dynamoDB.getTable("UserLogin");

    int UserID = 0;
    String UserName = "Patrick Laflin";
    int UserPassword = 18924;

    try {//from  w  w w. ja  va  2 s  .  com
        System.out.println("Adding a new item...");
        PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("UserID", UserID)
                .withString("User Name", UserName).withNumber("User Password", UserPassword));

        System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult());

    } catch (Exception e) {
        System.err.println("Unable to add item: " + UserID + " " + UserName);
        System.err.println(e.getMessage());
    }

}

From source file:AmazonDynamoDBSample_PutThrottled.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
 *//*  w  w  w  .  j  a  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
     * (/Users/haifengw/.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 (/Users/haifengw/.aws/credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    dynamoDB.setRegion(usWest2);
}

From source file:NYSEScan.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
 *///from ww w.  j  a  v  a 2 s.  c  o  m
private static void init() throws Exception {
    /*
     * The ProfileCredentialsProvider will return your [default] credential
     * profile by reading from the credentials file located at
     * (/Users/usdgadiraj/.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 (/Users/usdgadiraj/.aws/credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region region = Region.getRegion(Regions.US_EAST_1);
    dynamoDB.setRegion(region);
    dynamoDB.setEndpoint("http://dynamo.itversity.com:8000");
    dynamo = new DynamoDB(dynamoDB);
}

From source file:AmazonKinesisAuditVerify.java

License:Open Source License

public static void deleteResources() {
    AWSCredentials credentials = credentialsProvider.getCredentials();

    // Delete the stream
    AmazonKinesis kinesis = new AmazonKinesisClient(credentials);
    System.out.printf("Deleting the Amazon Kinesis stream used by the sample. Stream Name = %s.\n",
            SAMPLE_APPLICATION_STREAM_NAME);
    try {//w w w  .  j  a  va  2s  . c om
        kinesis.deleteStream(SAMPLE_APPLICATION_STREAM_NAME);
    } catch (ResourceNotFoundException ex) {
        // The stream doesn't exist.
    }

    // Delete the table
    AmazonDynamoDBClient dynamoDB = new AmazonDynamoDBClient(credentialsProvider.getCredentials());
    System.out.printf(
            "Deleting the Amazon DynamoDB table used by the Amazon Kinesis Client Library. Table Name = %s.\n",
            SAMPLE_APPLICATION_NAME);
    try {
        dynamoDB.deleteTable(SAMPLE_APPLICATION_NAME);
    } catch (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException ex) {
        // The table doesn't exist.
    }
}

From source file:TableCreator.java

License:Open Source License

private static void init() throws Exception {

    dynamoDB = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    dynamoDB.setRegion(usEast1);//from w w w .  j  a v a  2s  .  co  m
}

From source file:ProductCategoryPriceIndex.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
 *//*ww w.  ja  v  a 2 s .  c  o  m*/
private static void init() throws Exception {
    /*
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (/Users/usdgadiraj/.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 (/Users/usdgadiraj/.aws/credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    dynamoDB.setRegion(usWest2);
}

From source file:CreateUserLoginTable.java

License:Open Source License

public static void main(String[] args) throws Exception {

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());

    DynamoDB dynamoDB = new DynamoDB(client);

    String tableName = "UserLogin";

    try {// www .ja v  a 2s . co m
        System.out.println("Attempting to create table; please wait...");
        Table table = dynamoDB.createTable(tableName,
                Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key
                Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)),
                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:CreateUserFavoritesTable.java

License:Open Source License

public static void main(String[] args) throws Exception {

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());

    DynamoDB dynamoDB = new DynamoDB(client);

    String tableName = "UserFavorites";

    try {/* ww  w. j a  va  2 s.c om*/
        System.out.println("Attempting to create table; please wait...");
        Table table = dynamoDB.createTable(tableName,
                Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key
                Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)),
                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:VideoServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String url = request.getParameter("action");

    System.out.println("url" + url);

    Connection conn = null;//w ww. j a  va 2s. com
    Statement setupStatement;
    Statement readStatement = null;
    ResultSet resultSet = null;
    String results = "";
    int numresults = 0;
    String statement = null;
    List<Video> result = new ArrayList<>();

    try {

        // Create connection to RDS instance
        conn = DriverManager.getConnection(jdbcUrl);
        setupStatement = conn.createStatement();

        String retrieveVideoName = "select id from metadata where url like '" + url + "%';";

        ResultSet rs = setupStatement.executeQuery(retrieveVideoName);
        rs.next();
        String ids = rs.getString(1);
        String retrieveUrl = "select url from metadata where id =" + ids + ";";
        ResultSet ru = setupStatement.executeQuery(retrieveUrl);
        ru.next();
        String urls = ru.getString(1);
        System.out.println("este es el id:" + ids);
        System.out.println("esta es la url:" + urls);
        String[] urlIdeal = urls.split(".mp4");
        String finalUrl = urlIdeal[0] + ".mp4";
        System.out.println(finalUrl);

        AWSCredentials credentials = new PropertiesCredentials(
                new File("/Users/diana/Desktop/AwsCredentials.properties"));

        dynamoDBClient = new AmazonDynamoDBClient(new STSSessionCredentialsProvider(credentials));
        dynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2));
        String s = getItem(String.valueOf(ids));
        System.out.println(s);
        String[] textArray = s.split("\\{");

        String textFinal = textArray[3];
        String[] newTextArray = textFinal.split(",}");
        String textFinalFinal = newTextArray[0];
        String[] last = textFinalFinal.split("S:");

        System.out.println(last[1].trim());

        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Mp4Servlet</title>");
            out.println(" <script src=\"jquery-1.11.3.min.js\"></script>\n"
                    + "           <script type=\"text/javascript\" src=\"../libs/base64.js\"></script>\n"
                    + "   <script type=\"text/javascript\" src=\"../libs/sprintf.js\"></script>\n"
                    + "   <script type=\"text/javascript\" src=\"../jspdf.js\"></script>");
            out.println(" <style type=\"text/css\">\n" + "      body {\n" + "        padding-top: 20px;\n"
                    + "        padding-bottom: 40px;\n" + "      }\n" + "\n" + "        table{\n"
                    + "        display: table;\n" + "        border:black 5px solid;\n"
                    + "        border-collapse: separate;\n" + "        border-spacing: 7px;\n"
                    + "        border-color: gray;\n" + "        padding:2px;\n" + "\n" + "      }\n"
                    + "      \n" + "      #logo{\n" + "          height: 130px;\n" + "          width: 728px;\n"
                    + "      }\n" + "      hr{\n" + "        /*border-color:#357EC7;*/\n"
                    + "        border-color:#B6B6B4;\n" + "      }\n" + "\n" + "      /* Custom container */\n"
                    + "      .container-narrow {\n" + "        margin: 0 auto;\n"
                    + "        max-width: 700px;\n" + "      }\n" + "      .container-narrow > hr {\n"
                    + "        margin: 30px 0;\n" + "      }\n" + "\n" + "      /* Main marketing messages */\n"
                    + "      .jumbotron {\n" + "        margin: 60px 0;\n" + "        text-align: center;\n"
                    + "        color: grey;\n" + "      }\n" + "      .jumbotron h1 {\n"
                    + "        font-size: 72px;\n" + "        line-height: 1;\n" + "\n" + "      }\n"
                    + "      .jumbotron .btn {\n" + "        font-size: 21px;\n"
                    + "        padding: 14px 24px;\n" + "      }\n" + "\n"
                    + "      /* Supporting marketing content */\n" + "      .marketing {\n"
                    + "        margin: 60px 0;\n" + "      }\n" + "      .marketing p + h4 {\n"
                    + "        margin-top: 28px;\n" + "      }\n" + "      \n" + "      \n" + "      </style>\n"
                    + "      \n" + "\n"
                    + "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n"
                    + "");
            out.println("</head>");
            out.println("<body>");
            out.println("<div class=\"container-narrow\">\n"
                    + "       <img id = \"logo\" src=\"http://opennebula.org/wp-content/uploads/2015/05/IIT_Logo_stack_186_blk.png\">\n"
                    + "       </div>");
            out.println("<div class='jumbotron'></div>");
            out.println(
                    "<div class='container-narrow'> <video id='idtry'  controls preload='auto' width='500' height='200'></div>\n"
                            + "\n" + "   \n" + "      </video>");
            out.println(
                    "<div class='container-narrow'><br><button id ='button' type='button' class='btn btn-primary btn-lg' onclick='getText()'>EDIT</button></div>\n"
                            + "      <div>\n"
                            + "            <div class='container-narrow'><form id='usrform'><textarea id='text' class = 'container-narrow' name='comment' style='width: 400px; height: 200px;' form='usrform'></textarea>\n"
                            + "           <br><button id ='button2' type='button' onclick='submitToDynamo()'>Submit changes</button>\n"
                            + "            </form></div>\n" + "       </div>");

            out.println("<script>    \n" + "    var textA = " + "\"" + last[1].trim() + "\"" + ";\n" + "\n"
                    + "    document.getElementById('usrform').style.visibility = 'hidden';\n" + "    \n"
                    + "    function getText() {\n" + "\n" + "       var t = document.createTextNode(textA);\n"
                    + "       document.getElementById('text').appendChild(t);\n"
                    + "       document.getElementById('button').style.visibility = 'hidden';\n"
                    + "       document.getElementById('usrform').style.visibility = 'visible';\n" + "\n"
                    + "    }");

            out.println("  var x;\n" + "    function submitToDynamo() {\n" + "        \n"
                    + "       document.getElementById('usrform').style.visibility = 'hidden';\n"
                    + "       document.getElementById('button').style.visibility = 'visible';\n"
                    + "        x = document.getElementById('text').value;\n" + "      download(f,x);\n"
                    + "    }\n" + "       ");

            out.println("  function download(filename, text) {\n"
                    + "    var pom = document.createElement('a');\n"
                    + "    pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));\n"
                    + "    pom.setAttribute('download', filename);\n" + "\n"
                    + "    if (document.createEvent) {\n"
                    + "        var event = document.createEvent('MouseEvents');\n"
                    + "        event.initEvent('click', true, true);\n" + "        pom.dispatchEvent(event);\n"
                    + "    }\n" + "    else {\n" + "        pom.click();\n" + "    }\n" + "}\n" + "    \n"
                    + "    \n" + "var f = '/Users/diana/Desktop/texto.txt';");
            out.println("var code = '<source src=\"" + finalUrl + "\" type=\"video/mp4\" />';\n"
                    + "    document.getElementById(\"idtry\").innerHTML=code;");

            out.println("</script>");
            out.println("<div>");

            out.println("</div><br>");
            out.println("<a href='http://localhost:8080/studentUI/Uiservlet'>BACK TO LIST </a>");

            out.println("</body>");
            out.println("</html>");
        }

    } catch (SQLException ex) {
        // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    } finally {
        System.out.println("Closing the connection.");
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException ignore) {
            }
    }

}