List of usage examples for com.amazonaws AmazonServiceException getMessage
@Override
public String getMessage()
From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2DeleteSecurityGroupTask.java
License:Apache License
@TaskAction public void authorizeIngress() { // to enable conventionMappings feature String groupName = getGroupName(); String groupId = getGroupId(); AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class); AmazonEC2 ec2 = ext.getClient();//from w ww.j a v a 2 s .co m if (groupName == null && groupId == null) { throw new GradleException("groupName nor groupId is not specified"); } try { ec2.deleteSecurityGroup(new DeleteSecurityGroupRequest().withGroupId(groupId).withGroupName(groupName)); } catch (AmazonServiceException e) { if (e.getErrorCode().equals("InvalidPermission.Duplicate")) { getLogger().warn(e.getMessage()); } else { throw e; } } }
From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupEgressTask.java
License:Apache License
@TaskAction public void revokeEgress() { // to enable conventionMappings feature String groupId = getGroupId(); Object ipPermissions = getIpPermissions(); if (groupId == null) { throw new GradleException("groupId is not specified"); }/*from w w w .ja va 2s . c o m*/ if (ipPermissions == null) { throw new GradleException("ipPermissions is not specified"); } AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class); AmazonEC2 ec2 = ext.getClient(); try { ec2.revokeSecurityGroupEgress(new RevokeSecurityGroupEgressRequest().withGroupId(groupId) .withIpPermissions(parse(ipPermissions))); } catch (AmazonServiceException e) { if (e.getErrorCode().equals("InvalidPermission.NotFound")) { getLogger().warn(e.getMessage()); } else { throw e; } } }
From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupIngressTask.java
License:Apache License
@TaskAction public void revokeIngress() { // to enable conventionMappings feature String groupId = getGroupId(); Object ipPermissions = getIpPermissions(); if (groupId == null) { throw new GradleException("groupId is not specified"); }/*from ww w . j a va2s . c o m*/ if (ipPermissions == null) { throw new GradleException("ipPermissions is not specified"); } AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class); AmazonEC2 ec2 = ext.getClient(); try { ec2.revokeSecurityGroupIngress(new RevokeSecurityGroupIngressRequest().withGroupId(groupId) .withIpPermissions(parse(ipPermissions))); } catch (AmazonServiceException e) { if (e.getErrorCode().equals("InvalidPermission.NotFound")) { getLogger().warn(e.getMessage()); } else { throw e; } } }
From source file:jp.classmethod.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCreateApplicationVersionTask.java
License:Apache License
@TaskAction public void createVersion() { // to enable conventionMappings feature String appName = getAppName(); String versionLabel = getVersionLabel(); AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class); AWSElasticBeanstalk eb = ext.getClient(); try {//from ww w . j a v a 2 s.com eb.createApplicationVersion(new CreateApplicationVersionRequest().withApplicationName(appName) .withVersionLabel(versionLabel).withSourceBundle(new S3Location(getBucketName(), getKey()))); getLogger().info("version " + versionLabel + " @ " + appName + " created"); } catch (AmazonServiceException e) { if (!e.getMessage().contains("already exists.")) { throw e; } getLogger().warn("version " + versionLabel + " @ " + appName + " already exists."); } }
From source file:jp.classmethod.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkTerminateEnvironmentTask.java
License:Apache License
@TaskAction public void terminateEnvironment() { // to enable conventionMappings feature String appName = getAppName(); String envName = getEnvName(); String envId = getEnvId();/*from w w w .ja v a 2 s .c o m*/ AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class); AWSElasticBeanstalk eb = ext.getClient(); if (envId == null) { DescribeEnvironmentsResult der = eb.describeEnvironments( new DescribeEnvironmentsRequest().withApplicationName(appName).withEnvironmentNames(envName)); if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) { getLogger().warn("environment " + envName + " @ " + appName + " not found"); return; } EnvironmentDescription ed = der.getEnvironments().get(0); envId = ed.getEnvironmentId(); } try { eb.terminateEnvironment( new TerminateEnvironmentRequest().withEnvironmentId(envId).withEnvironmentName(envName)); getLogger().info("environment " + envName + " (" + envId + ") @ " + appName + " termination requested"); } catch (AmazonServiceException e) { if (e.getMessage().contains("No Environment found") == false) { throw e; } getLogger().warn("environment " + envName + " (" + envId + ") @ " + appName + " not found"); } }
From source file:jp.dqneo.amazons3.sample.S3Sample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*w w w .j av a2s . c o m*/ * 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 */ AmazonS3 s3 = new AmazonS3Client( new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties"))); s3.setEndpoint("https://s3-ap-northeast-1.amazonaws.com"); String bucketName = "my-first-s3-bucket-" + UUID.randomUUID(); String key = "2/foo/bar"; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); try { /* * Upload an object to your bucket - You can easily upload a file to * S3, or upload directly an InputStream if you know the length of * the data in the stream. You can also specify your own metadata * when uploading to S3, which allows you set a variety of options * like content-type and content-encoding, plus additional metadata * specific to your applications. */ System.out.println("Uploading a new object to S3 from a file\n"); PutObjectRequest p = new PutObjectRequest(bucketName, key, createSampleFile()); s3.putObject(p); System.out.println("ok\n"); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon S3, 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 S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:jp.primecloud.auto.aws.wrapper.ExceptionHandleAwsClientWrapper.java
License:Open Source License
protected AutoException handleException(AmazonServiceException exception, Method method, Object[] args) { Object request = null;/*from ww w.j a v a 2 s . co m*/ if (method.getParameterTypes().length > 0) { request = args[0]; } // UserData?????????? if (request instanceof RunInstancesRequest) { ((RunInstancesRequest) request).setUserData(null); } String str = StringUtils.reflectToString(request); return new AutoException("EAWS-000003", exception, method.getName(), exception.getErrorCode(), exception.getMessage(), str); }
From source file:main.java.ddb.loader.DDBLoaderUtils.java
License:Apache License
static void createTable() throws Exception { try {/*from ww w .j a va 2 s .co m*/ CreateTableRequest create_req = new CreateTableRequest().withTableName(DDBSampleLoader.TBL_NAME) .withKeySchema(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Id") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(DDBSampleLoader.RCU) .withWriteCapacityUnits(DDBSampleLoader.WCU)); DDBSampleLoader.log.info("Creating a new table ..."); TableUtils.createTableIfNotExists(DDBSampleLoader.ddb_client, create_req); DDBSampleLoader.log.info("Waiting for the table status to be 'ACTIVE' ..."); TableUtils.waitUntilActive(DDBSampleLoader.ddb_client, DDBSampleLoader.TBL_NAME); } catch (AmazonServiceException e) { DDBSampleLoader.log.error("Caught an AmazonServiceException ..."); DDBSampleLoader.log.error("Error Message: " + e.getMessage()); DDBSampleLoader.log.error("HTTP Status Code: " + e.getStatusCode()); DDBSampleLoader.log.error("AWS Error Code: " + e.getErrorCode()); DDBSampleLoader.log.error("Error Type: " + e.getErrorType()); DDBSampleLoader.log.error("Request ID: " + e.getRequestId()); } catch (AmazonClientException e) { DDBSampleLoader.log.error("Caught an AmazonClientException ..."); DDBSampleLoader.log.error("Error Message: " + e.getMessage()); } }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
private void logAmazonServiceException(AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason." + " Error Message: " + ase.getMessage() + " HTTP Status Code: " + ase.getStatusCode() + " AWS Error Code: " + ase.getErrorCode() + " Error Type: " + ase.getErrorType() + " Request ID: " + ase.getRequestId(), ase);/*w w w. j av a2 s . co m*/ }
From source file:n3phele.agent.repohandlers.S3Large.java
License:Open Source License
public Origin put(InputStream input, long length, String encoding) { Origin result = new Origin(source + "/" + root + "/" + key, 0, null, null); TransferManager tm = null;//w w w . j a v a 2 s .c o m try { tm = new TransferManager(this.credentials); tm.getAmazonS3Client().setEndpoint(source.toString()); objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(this.length = length); this.encoding = encoding; if (encoding != null) objectMetadata.setContentType(this.encoding); log.info("Output: " + source + "/" + root + "/" + key + " Content-Type: " + encoding + "length: " + length); Upload upload = tm.upload(root, key, input, objectMetadata); upload.waitForCompletion(); // PutObjectResult object = s3().putObject(root, key, input, objectMetadata); result.setLength(length); ObjectMetadata od = s3().getObjectMetadata(root, key); result.setModified(od.getLastModified()); } catch (AmazonServiceException e) { throw e; } catch (AmazonClientException e) { throw e; } catch (InterruptedException e) { throw new AmazonClientException(e.getMessage()); } finally { try { input.close(); } catch (IOException e) { } try { tm.shutdownNow(); } catch (Exception e) { } try { s3().shutdown(); } catch (Exception e) { } } return result; }