use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class S3Cors method deleteBucketCorsInformation.
// snippet-start:[s3.java2.cors.main]
public static void deleteBucketCorsInformation(S3Client s3, String bucketName, String accountId) {
try {
DeleteBucketCorsRequest bucketCorsRequest = DeleteBucketCorsRequest.builder().bucket(bucketName).expectedBucketOwner(accountId).build();
s3.deleteBucketCors(bucketCorsRequest);
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class S3ObjectOperations method createBucket.
// Create a bucket by using a S3Waiter object
public static void createBucket(S3Client s3Client, String bucketName, Region region) {
S3Waiter s3Waiter = s3Client.waiter();
try {
CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).createBucketConfiguration(CreateBucketConfiguration.builder().locationConstraint(region.id()).build()).build();
s3Client.createBucket(bucketRequest);
HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
// Wait until the bucket is created and print out the response
WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
waiterResponse.matched().response().ifPresent(System.out::println);
System.out.println(bucketName + " is ready");
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class S3ObjectOperations method deleteBucket.
public static void deleteBucket(S3Client client, String bucket) {
DeleteBucketRequest deleteBucketRequest = DeleteBucketRequest.builder().bucket(bucket).build();
client.deleteBucket(deleteBucketRequest);
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class SetAcl method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <bucketName> <id> \n\n" + "Where:\n" + " bucketName - the Amazon S3 bucket to grant permissions on. \n" + " id - the ID of the owner of this bucket (you can get this value from the AWS Management Console).\n";
if (args.length != 3) {
System.out.println(USAGE);
System.exit(1);
}
String bucketName = args[0];
String id = args[1];
System.out.format("Setting access \n");
System.out.println(" in bucket: " + bucketName);
Region region = Region.US_WEST_2;
S3Client s3 = S3Client.builder().region(region).build();
setBucketAcl(s3, bucketName, id);
System.out.println("Done!");
s3.close();
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class SetAcl method setBucketAcl.
// snippet-start:[s3.java2.set_acl.main]
public static void setBucketAcl(S3Client s3, String bucketName, String id) {
try {
Grant ownerGrant = Grant.builder().grantee(builder -> {
builder.id(id).type(Type.CANONICAL_USER);
}).permission(Permission.FULL_CONTROL).build();
List<Grant> grantList2 = new ArrayList<>();
grantList2.add(ownerGrant);
AccessControlPolicy acl = AccessControlPolicy.builder().owner(builder -> builder.id(id)).grants(grantList2).build();
PutBucketAclRequest putAclReq = PutBucketAclRequest.builder().bucket(bucketName).accessControlPolicy(acl).build();
s3.putBucketAcl(putAclReq);
} catch (S3Exception e) {
e.printStackTrace();
System.exit(1);
}
}
Aggregations