use of com.amazonaws.services.s3.model.DeleteBucketRequest in project aws-doc-sdk-examples by awsdocs.
the class S3BucketDeletion method listAllObjects.
// snippet-start:[s3.java2.s3_bucket_ops.delete_bucket]
public static void listAllObjects(S3Client s3, String bucket) {
try {
// To delete a bucket, all the objects in the bucket must be deleted first
ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder().bucket(bucket).build();
ListObjectsV2Response listObjectsV2Response;
do {
listObjectsV2Response = s3.listObjectsV2(listObjectsV2Request);
for (S3Object s3Object : listObjectsV2Response.contents()) {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucket).key(s3Object.key()).build());
}
listObjectsV2Request = ListObjectsV2Request.builder().bucket(bucket).continuationToken(listObjectsV2Response.nextContinuationToken()).build();
} while (listObjectsV2Response.isTruncated());
// snippet-end:[s3.java2.s3_bucket_ops.delete_bucket]
DeleteBucketRequest deleteBucketRequest = DeleteBucketRequest.builder().bucket(bucket).build();
s3.deleteBucket(deleteBucketRequest);
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of com.amazonaws.services.s3.model.DeleteBucketRequest 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 com.amazonaws.services.s3.model.DeleteBucketRequest in project camel by apache.
the class S3Producer method deleteBucket.
private void deleteBucket(AmazonS3 s3Client, Exchange exchange) {
String bucketName;
bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
if (ObjectHelper.isEmpty(bucketName)) {
bucketName = getConfiguration().getBucketName();
}
DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest(bucketName);
s3Client.deleteBucket(deleteBucketRequest);
}
use of com.amazonaws.services.s3.model.DeleteBucketRequest in project nifi by apache.
the class AbstractS3IT method oneTimeTearDown.
@AfterClass
public static void oneTimeTearDown() {
// Empty the bucket before deleting it.
try {
ObjectListing objectListing = client.listObjects(BUCKET_NAME);
while (true) {
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
client.deleteObject(BUCKET_NAME, objectSummary.getKey());
}
if (objectListing.isTruncated()) {
objectListing = client.listNextBatchOfObjects(objectListing);
} else {
break;
}
}
DeleteBucketRequest dbr = new DeleteBucketRequest(BUCKET_NAME);
client.deleteBucket(dbr);
} catch (final AmazonS3Exception e) {
System.err.println("Unable to delete bucket " + BUCKET_NAME + e.toString());
}
if (client.doesBucketExist(BUCKET_NAME)) {
Assert.fail("Incomplete teardown, subsequent tests might fail");
}
}
Aggregations