use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class SetAcl method setBucketAcl.
public static void setBucketAcl(String bucket_name, String email, String access) {
System.out.format("Setting %s access for %s\n", access, email);
System.out.println("on bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
// get the current ACL
AccessControlList acl = s3.getBucketAcl(bucket_name);
// set access for the grantee
EmailAddressGrantee grantee = new EmailAddressGrantee(email);
Permission permission = Permission.valueOf(access);
acl.grantPermission(grantee, permission);
s3.setBucketAcl(bucket_name, acl);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class SetAcl method setObjectAcl.
public static void setObjectAcl(String bucket_name, String object_key, String email, String access) {
System.out.format("Setting %s access for %s\n", access, email);
System.out.println("for object: " + object_key);
System.out.println(" in bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
// get the current ACL
AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
// set access for the grantee
EmailAddressGrantee grantee = new EmailAddressGrantee(email);
Permission permission = Permission.valueOf(access);
acl.grantPermission(grantee, permission);
s3.setObjectAcl(bucket_name, object_key, acl);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class DeleteObject method main.
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);
}
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 = AmazonS3ClientBuilder.defaultClient();
try {
s3.deleteObject(bucket_name, object_key);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class GetAcl method getBucketAcl.
public static void getBucketAcl(String bucket_name) {
System.out.println("Retrieving ACL for bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
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);
}
}
use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class GetAcl method getObjectAcl.
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 {
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);
}
}
Aggregations