List of usage examples for com.amazonaws AmazonServiceException getStatusCode
public int getStatusCode()
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void describeVolumes() { try {/*from ww w . ja v a 2 s .c om*/ DescribeVolumesResult volumesResult = ec2.describeVolumes(); System.out.println("You have access to " + volumesResult.getVolumes().size() + " Volumes."); for (Volume vol : volumesResult.getVolumes()) { System.out.println(vol); } } catch (AmazonServiceException ase) { System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void CreateNewInstance(String imageId, String instanceType, List<String> securityGroups, String userData) {//from w w w . java2 s. c om try { RunInstancesRequest crir = new RunInstancesRequest(); crir.setImageId(imageId); crir.setInstanceType(instanceType); crir.setSecurityGroups(securityGroups); crir.setKeyName("hpdefault"); if (userData != null) { crir.setUserData(userData); } RunInstancesResult result = ec2.runInstances(crir); System.out.println(result); String instanceId = null; List<Instance> instances = result.getReservation().getInstances(); for (Instance instance : instances) { instanceId = instance.getInstanceId(); } // HACKHACK sleep for 5 seconds so the private ip gets assigned System.out.println("Sleeping for 5 to wait for the private ip"); try { Thread.sleep(5000); } catch (InterruptedException ignore) { ignore.printStackTrace(); } String publicIp = assignPublicIp(instanceId); System.out.println("Public IP: " + publicIp); System.out.println("Instance State: " + getInstanceState(instanceId)); } catch (AmazonServiceException ase) { System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void TerminateInstance(String instanceId) { try {//from www .j ava 2s .com TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest(); List<String> instanceIds = new ArrayList<String>(); instanceIds.add(instanceId); terminateRequest.setInstanceIds(instanceIds); TerminateInstancesResult result = ec2.terminateInstances(terminateRequest); System.out.println(result); } catch (AmazonServiceException ase) { System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void CreateSecurityGroup(String name, String description) throws Exception { try {/* w ww.ja v a2 s . c om*/ CreateSecurityGroupRequest newSecurityGroup = new CreateSecurityGroupRequest(); newSecurityGroup.setDescription(description); newSecurityGroup.setGroupName(name); ec2.createSecurityGroup(newSecurityGroup); System.out.println("Security group created : " + name); } catch (AmazonServiceException ase) { System.out.println("Error : Adding new security group"); System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void DeleteSecurityGroup(String name) throws Exception { try {//from www . j ava 2 s . co m DeleteSecurityGroupRequest deleteSecurityGroupRequest = new DeleteSecurityGroupRequest(name); // newSecurityGroup.setDescription(name); // newSecurityGroup.setGroupName(description); ec2.deleteSecurityGroup(deleteSecurityGroupRequest); System.out.println("Security group deleted : " + name); } catch (AmazonServiceException ase) { System.out.println("Error : Adding new security group"); System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void AddSecurityPorts(List<Integer> ports, String securityGroupName) throws Exception { for (Integer port : ports) { try {//from w ww. j av a 2s . co m AuthorizeSecurityGroupIngressRequest securityPortsRequest = new AuthorizeSecurityGroupIngressRequest(); securityPortsRequest.setFromPort(port); securityPortsRequest.setIpProtocol("tcp"); securityPortsRequest.setToPort(port); securityPortsRequest.setGroupName(securityGroupName); ec2.authorizeSecurityGroupIngress(securityPortsRequest); System.out.println("Added Access to port " + port.toString()); } catch (AmazonServiceException ase) { System.out.println("Error : Adding access to port " + port.toString()); System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } } }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void printAllSecurityGroups() throws Exception { try {/*from w w w . java2s .c o m*/ DescribeSecurityGroupsResult securityResult = ec2.describeSecurityGroups(); for (SecurityGroup security : securityResult.getSecurityGroups()) { System.out.println(security); } } catch (AmazonServiceException ase) { System.out.println("Error : Printing out security group"); System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
License:Open Source License
public static void RevokeSecurityPort(int fromPort, int toPort, String securityGroupName) throws Exception { try {/* www . ja va 2s .c o m*/ RevokeSecurityGroupIngressRequest revokeRequest = new RevokeSecurityGroupIngressRequest(); revokeRequest.setFromPort(fromPort); revokeRequest.setIpProtocol("tcp"); revokeRequest.setToPort(toPort); revokeRequest.setGroupName(securityGroupName); ec2.revokeSecurityGroupIngress(revokeRequest); System.out.println( "Security port revoked successfully. from port (" + fromPort + ") - to port(" + toPort + ")"); } catch (AmazonServiceException ase) { System.out.println( "Error : revoking security port : from port(" + fromPort + ") - to port(" + toPort + ")"); System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:com.hrt.modules.aws.sns.SNSMobilePush.java
License:Open Source License
public static void main(String[] args) throws IOException { /*// w w w .j a va 2s .c o m * TODO: 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 */ // AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( // SNSMobilePush.class.getResourceAsStream("AwsCredentials.properties"))); AmazonSNS sns = new AmazonSNSClient( new AccessCredentials("AKIAJGE6YKV7ZOB2BU2Q", "VHNI9fZcMQirkslT9juVpodG4Mf94ixv7CXRuc4s")); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); System.out.println("===========================================\n"); System.out.println("Getting Started with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); /* TODO: Uncomment the services you wish to use. */ // sample.demoAndroidAppNotification(); // sample.demoKindleAppNotification(); sample.demoAppleAppNotification(); // sample.demoAppleSandboxAppNotification(); // sample.demoBaiduAppNotification(); // sample.demoWNSAppNotification(); // sample.demoMPNSAppNotification(); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, 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 SNS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.hussi.aws.dynamoDB.AmazonDynamoDBSample.java
License:Open Source License
public static void main(String[] args) throws Exception { init();/*from w w w .ja va2 s . c o m*/ try { String tableName = "hussi_first_dynamo_table"; // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); // Create table if it does not exist yet TableUtils.createTableIfNotExists(dynamoDB, createTableRequest); // wait for the table to move into ACTIVE state TableUtils.waitUntilActive(dynamoDB, tableName); // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); // Add an item Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara"); PutItemRequest putItemRequest = new PutItemRequest(tableName, item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Add another item item = newItem("Airplane", 1980, "*****", "James", "Billy Bob"); putItemRequest = new PutItemRequest(tableName, item); putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, 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 AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }