List of usage examples for com.amazonaws.regions Regions US_WEST_2
Regions US_WEST_2
To view the source code for com.amazonaws.regions Regions US_WEST_2.
Click Source Link
From source file:SimpleDBExample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*// w ww. ja v a2s .c o m * This credentials provider implementation loads your AWS credentials * from a properties file at the root of your classpath. * * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider()); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sdb.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SimpleDB"); System.out.println("===========================================\n"); try { // Create a domain String myDomain = "MyStore"; System.out.println("Creating domain called " + myDomain + ".\n"); sdb.createDomain(new CreateDomainRequest(myDomain)); // List domains System.out.println("Listing all domains in your account:\n"); for (String domainName : sdb.listDomains().getDomainNames()) { System.out.println(" " + domainName); } System.out.println(); // Put data into a domain System.out.println("Putting data into " + myDomain + " domain.\n"); sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData())); // Select data from a domain // Notice the use of backticks around the domain name in our select expression. String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'"; System.out.println("Selecting: " + selectExpression + "\n"); SelectRequest selectRequest = new SelectRequest(selectExpression); for (Item item : sdb.select(selectRequest).getItems()) { System.out.println(" Item"); System.out.println(" Name: " + item.getName()); for (Attribute attribute : item.getAttributes()) { System.out.println(" Attribute"); System.out.println(" Name: " + attribute.getName()); System.out.println(" Value: " + attribute.getValue()); } } System.out.println(); // Delete values from an attribute System.out.println("Deleting Blue attributes in Item_O3.\n"); Attribute deleteValueAttribute = new Attribute("Color", "Blue"); sdb.deleteAttributes( new DeleteAttributesRequest(myDomain, "Item_03").withAttributes(deleteValueAttribute)); // Delete an attribute and all of its values System.out.println("Deleting attribute Year in Item_O3.\n"); sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03") .withAttributes(new Attribute().withName("Year"))); // Replace an attribute System.out.println("Replacing Size of Item_03 with Medium.\n"); List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>(); replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true)); sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes)); // Delete an item and all of its attributes System.out.println("Deleting Item_03.\n"); sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")); // Delete a domain System.out.println("Deleting " + myDomain + " domain.\n"); sdb.deleteDomain(new DeleteDomainRequest(myDomain)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SimpleDB, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SimpleDB, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:SimpleDBWrite.java
License:Open Source License
public static void run(String searchItem) throws Exception { /*/*from w w w . j a v a 2 s . c o m*/ * This credentials provider implementation loads your AWS credentials * from a properties file at the root of your classpath. * * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider()); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sdb.setRegion(usWest2); try { // Create a domain String myDomain = "WanningStore"; sdb.createDomain(new CreateDomainRequest(myDomain)); // List domains // System.out.println("Listing all domains in your account:\n"); // for (String domainName : sdb.listDomains().getDomainNames()) { // System.out.println(" " + domainName); // } // System.out.println(); // Put data into a domain System.out.println("Putting data into " + myDomain + " domain.\n"); sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createData(searchItem))); // // Delete values from an attribute // System.out.println("Deleting Blue attributes in Item_O3.\n"); // Attribute deleteValueAttribute = new Attribute("Color", "Blue"); // sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03") // .withAttributes(deleteValueAttribute)); // Delete an attribute and all of its values // System.out.println("Deleting attribute Year in Item_O3.\n"); // sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03") // .withAttributes(new Attribute().withName("Year"))); // // // Replace an attribute // System.out.println("Replacing Size of Item_03 with Medium.\n"); // List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>(); // replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true)); // sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes)); // // // Delete an item and all of its attributes // System.out.println("Deleting Item_03.\n"); // sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")); // // // Delete a domain // System.out.println("Deleting " + myDomain + " domain.\n"); // sdb.deleteDomain(new DeleteDomainRequest(myDomain)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SimpleDB, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SimpleDB, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.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 *///from w ww . j a va 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/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:AwsSQSDemo.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//w w w. ja v a 2s .c om * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().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 (~/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageRecieptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
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 *//*from www. j a v a 2 s. co 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:InlineGettingStartedCodeSampleApp.java
License:Open Source License
public static void main(String[] args) { //============================================================================================// //=============================== Submitting a Request =======================================// //============================================================================================// /*// w ww . j a va 2 s . c om * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/Users/zunzunwang/.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/zunzunwang/.aws/credentials), and is in valid format.", e); } // Create the AmazonEC2Client object so we can call various APIs. AmazonEC2 ec2 = new AmazonEC2Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); ec2.setRegion(usWest2); // Initializes a Spot Instance Request RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest(); // Request 1 x t1.micro instance with a bid price of $0.03. requestRequest.setSpotPrice("0.03"); requestRequest.setInstanceCount(Integer.valueOf(1)); // Setup the specifications of the launch. This includes the instance type (e.g. t1.micro) // and the latest Amazon Linux AMI id available. Note, you should always use the latest // Amazon Linux AMI id or another of your choosing. LaunchSpecification launchSpecification = new LaunchSpecification(); launchSpecification.setImageId("ami-8c1fece5"); launchSpecification.setInstanceType("t1.micro"); // Add the security group to the request. ArrayList<String> securityGroups = new ArrayList<String>(); securityGroups.add("GettingStartedGroup"); launchSpecification.setSecurityGroups(securityGroups); // Add the launch specifications to the request. requestRequest.setLaunchSpecification(launchSpecification); //============================================================================================// //=========================== Getting the Request ID from the Request ========================// //============================================================================================// // Call the RequestSpotInstance API. RequestSpotInstancesResult requestResult = ec2.requestSpotInstances(requestRequest); List<SpotInstanceRequest> requestResponses = requestResult.getSpotInstanceRequests(); // Setup an arraylist to collect all of the request ids we want to watch hit the running // state. ArrayList<String> spotInstanceRequestIds = new ArrayList<String>(); // Add all of the request ids to the hashset, so we can determine when they hit the // active state. for (SpotInstanceRequest requestResponse : requestResponses) { System.out.println("Created Spot Request: " + requestResponse.getSpotInstanceRequestId()); spotInstanceRequestIds.add(requestResponse.getSpotInstanceRequestId()); } //============================================================================================// //=========================== Determining the State of the Spot Request ======================// //============================================================================================// // Create a variable that will track whether there are any requests still in the open state. boolean anyOpen; // Initialize variables. ArrayList<String> instanceIds = new ArrayList<String>(); do { // Create the describeRequest with tall of the request id to monitor (e.g. that we started). DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest(); describeRequest.setSpotInstanceRequestIds(spotInstanceRequestIds); // Initialize the anyOpen variable to false, which assumes there are no requests open unless // we find one that is still open. anyOpen = false; try { // Retrieve all of the requests we want to monitor. DescribeSpotInstanceRequestsResult describeResult = ec2 .describeSpotInstanceRequests(describeRequest); List<SpotInstanceRequest> describeResponses = describeResult.getSpotInstanceRequests(); // Look through each request and determine if they are all in the active state. for (SpotInstanceRequest describeResponse : describeResponses) { // If the state is open, it hasn't changed since we attempted to request it. // There is the potential for it to transition almost immediately to closed or // cancelled so we compare against open instead of active. if (describeResponse.getState().equals("open")) { anyOpen = true; break; } // Add the instance id to the list we will eventually terminate. instanceIds.add(describeResponse.getInstanceId()); } } catch (AmazonServiceException e) { // If we have an exception, ensure we don't break out of the loop. // This prevents the scenario where there was blip on the wire. anyOpen = true; } try { // Sleep for 60 seconds. Thread.sleep(60 * 1000); } catch (Exception e) { // Do nothing because it woke up early. } } while (anyOpen); //============================================================================================// //====================================== Canceling the Request ==============================// //============================================================================================// try { // Cancel requests. CancelSpotInstanceRequestsRequest cancelRequest = new CancelSpotInstanceRequestsRequest( spotInstanceRequestIds); ec2.cancelSpotInstanceRequests(cancelRequest); } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.println("Error cancelling instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); } //============================================================================================// //=================================== Terminating any Instances ==============================// //============================================================================================// try { // Terminate instances. TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest(instanceIds); ec2.terminateInstances(terminateRequest); } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.println("Error terminating instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); } }
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;/*from w ww .ja v a 2s . c o m*/ 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) { } } }
From source file:AmazonDynamoDBSample.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 .java 2 s . co m private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/home/madhurima/.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 (/home/madhurima/.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:CreateSecurityGroupApp.java
License:Open Source License
public static void main(String[] args) { /*/*from w w w. ja v a 2 s . com*/ * The ProfileCredentialsProvider will return your [New Profile] * credential profile by reading from the credentials file located at * (C:\\Users\\Accolite\\.aws\\credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("New Profile").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\\Accolite\\.aws\\credentials), and is in valid format.", e); } // Create the AmazonEC2Client object so we can call various APIs. AmazonEC2 ec2 = new AmazonEC2Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); ec2.setRegion(usWest2); // Create a new security group. try { CreateSecurityGroupRequest securityGroupRequest = new CreateSecurityGroupRequest("Muneer_SG", "My Security Group"); CreateSecurityGroupResult result = ec2.createSecurityGroup(securityGroupRequest); System.out.println(String.format("Security group created: [%s]", result.getGroupId())); } catch (AmazonServiceException ase) { // Likely this means that the group is already created, so ignore. System.out.println(ase.getMessage()); } String ipAddr = "0.0.0.0/0"; // Get the IP of the current host, so that we can limit the Security Group // by default to the ip range associated with your subnet. try { InetAddress addr = InetAddress.getLocalHost(); // Get IP Address ipAddr = addr.getHostAddress() + "/10"; } catch (UnknownHostException e) { } // Create a range that you would like to populate. List<String> ipRanges = Collections.singletonList(ipAddr); // Open up port 23 for TCP traffic to the associated IP from above (e.g. ssh traffic). IpPermission ipPermission = new IpPermission().withIpProtocol("tcp").withFromPort(new Integer(22)) .withToPort(new Integer(22)).withIpRanges(ipRanges); List<IpPermission> ipPermissions = Collections.singletonList(ipPermission); try { // Authorize the ports to the used. AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSecurityGroupIngressRequest( "GettingStartedGroup", ipPermissions); ec2.authorizeSecurityGroupIngress(ingressRequest); System.out.println(String.format("Ingress port authroized: [%s]", ipPermissions.toString())); } catch (AmazonServiceException ase) { // Ignore because this likely means the zone has already been authorized. System.out.println(ase.getMessage()); } }
From source file:RandomQuery1OnDynamoDB.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. * //from w w w . j a v a 2s.c o m * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration */ private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (C:\\Users\\Divendar\\.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\\Divendar\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); }