Example usage for com.amazonaws AmazonServiceException getErrorMessage

List of usage examples for com.amazonaws AmazonServiceException getErrorMessage

Introduction

In this page you can find the example usage for com.amazonaws AmazonServiceException getErrorMessage.

Prototype

public String getErrorMessage() 

Source Link

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   w  ww .  j  av a 2  s  .co 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:aws.example.s3.CopyObject.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name (key) of an S3 object, the bucket name\n"
            + "that it's contained within, and the bucket to copy it to.\n" + "\n"
            + "Ex: CopyObject <objectname> <frombucket> <tobucket>\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);//from  ww w  . ja v a2  s.  c o m
    }

    String object_key = args[0];
    String from_bucket = args[1];
    String to_bucket = args[2];

    System.out.format("Copying object %s from bucket %s to %s\n", object_key, from_bucket, to_bucket);
    final AmazonS3 s3 = new AmazonS3Client();
    try {
        s3.copyObject(from_bucket, object_key, to_bucket, object_key);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.s3.CreateBucket.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name of a bucket to create!\n"
            + "Ex: CreateBucket <unique-bucket-name>\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);/*from   w w w. jav  a 2s  .com*/
    }

    String bucket_name = args[0];

    System.out.println("Creating S3 bucket: " + bucket_name);
    final AmazonS3 s3 = new AmazonS3Client();
    try {
        Bucket b = s3.createBucket(bucket_name);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.s3.DeleteBucket.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket\n" + "\n"
            + "Ex: DeleteBucket <bucketname>\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);/*w  w  w  .  ja v  a  2s.co m*/
    }

    String bucket_name = args[0];

    System.out.println("Deleting S3 bucket: " + bucket_name);
    final AmazonS3 s3 = new AmazonS3Client();

    try {
        System.out.println(" - removing objects from bucket");
        ObjectListing object_listing = s3.listObjects(bucket_name);
        while (true) {
            for (Iterator<?> iterator = object_listing.getObjectSummaries().iterator(); iterator.hasNext();) {
                S3ObjectSummary summary = (S3ObjectSummary) iterator.next();
                s3.deleteObject(bucket_name, summary.getKey());
            }

            // more object_listing to retrieve?
            if (object_listing.isTruncated()) {
                object_listing = s3.listNextBatchOfObjects(object_listing);
            } else {
                break;
            }
        }
        ;

        System.out.println(" - removing versions from bucket");
        VersionListing version_listing = s3.listVersions(new ListVersionsRequest().withBucketName(bucket_name));
        while (true) {
            for (Iterator<?> iterator = version_listing.getVersionSummaries().iterator(); iterator.hasNext();) {
                S3VersionSummary vs = (S3VersionSummary) iterator.next();
                s3.deleteVersion(bucket_name, vs.getKey(), vs.getVersionId());
            }

            if (version_listing.isTruncated()) {
                version_listing = s3.listNextBatchOfVersions(version_listing);
            } else {
                break;
            }
        }

        System.out.println(" OK, bucket ready to delete!");
        s3.deleteBucket(bucket_name);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.s3.DeleteBucketPolicy.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    DeleteBucketPolicy <bucket>\n\n" + "Where:\n"
            + "    bucket - the bucket to delete the policy from.\n\n" + "Example:\n"
            + "    DeleteBucketPolicy testbucket\n\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);/* www  .j av a2 s.  co m*/
    }

    String bucket_name = args[0];
    String policy_text = null;

    System.out.format("Deleting policy from bucket: \"%s\"\n\n", bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        s3.deleteBucketPolicy(bucket_name);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }

    System.out.println("Done!");
}

From source file:aws.example.s3.DeleteObject.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket and object\n"
            + "name (key) to delete.\n" + "\n" + "Ex: DeleteObject <bucketname> <objectname>\n";

    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);/*w  w  w.  j  a  va  2s.  co  m*/
    }

    String bucket_name = args[0];
    String object_key = args[1];

    System.out.format("Deleting object %s from S3 bucket: %s\n", object_key, bucket_name);
    final AmazonS3 s3 = new AmazonS3Client();
    try {
        s3.deleteObject(bucket_name, object_key);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.s3.DeleteObjects.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket and at least\n"
            + "one object name (key) to delete.\n" + "\n"
            + "Ex: DeleteObjects <bucketname> <objectname1> [objectname2, ...]\n";

    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);/*from w  ww.j  a v a  2  s .c o  m*/
    }

    String bucket_name = args[0];
    String[] object_keys = Arrays.copyOfRange(args, 1, args.length);

    System.out.println("Deleting objects from S3 bucket: " + bucket_name);
    for (String k : object_keys) {
        System.out.println(" * " + k);
    }

    final AmazonS3 s3 = new AmazonS3Client();
    try {
        DeleteObjectsRequest dor = new DeleteObjectsRequest(bucket_name).withKeys(object_keys);
        s3.deleteObjects(dor);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.s3.DeleteWebsiteConfiguration.java

License:Open Source License

public static void deleteWebsiteConfig(String bucket_name) {
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {/*w w w  .ja  va  2 s  . c  om*/
        s3.deleteBucketWebsiteConfiguration(bucket_name);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.out.println("Failed to delete website configuration!");
        System.exit(1);
    }
}

From source file:aws.example.s3.GetAcl.java

License:Open Source License

public static void getBucketAcl(String bucket_name) {
    System.out.println("Retrieving ACL for bucket: " + bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {//  w w w.j ava2s. c  om
        AccessControlList acl = s3.getBucketAcl(bucket_name);
        List<Grant> grants = acl.getGrantsAsList();
        for (Grant grant : grants) {
            System.out.format("  %s: %s\n", grant.getGrantee().getIdentifier(),
                    grant.getPermission().toString());
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}

From source file:aws.example.s3.GetAcl.java

License:Open Source License

public static void getObjectAcl(String bucket_name, String object_key) {
    System.out.println("Retrieving ACL for object: " + object_key);
    System.out.println("                in bucket: " + bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {//from  w w w . j a v  a  2s  .co m
        AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
        List<Grant> grants = acl.getGrantsAsList();
        for (Grant grant : grants) {
            System.out.format("  %s: %s\n", grant.getGrantee().getIdentifier(),
                    grant.getPermission().toString());
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}