For deleting a bucket, the primary condition is that the bucket should be empty. So we will now see how to delete the object, the folder, and then the bucket. To delete an object/folder, execute the following command:
s3.deleteObject(bucketName, OBJECT_KEY_OR_FOLDER_NAME);
Or execute the following command:
s3.deleteObject(new DeleteObjectRequest(bucketName, OBJECT_KEY_OR_FOLDER_NAME));
Replace bucketName
with the actual bucket name and OBJECT_KEY_OR_FOLDER_NAME
with either your object key or the name of the folder that is supposed to be deleted.
The complete code for delete operations on buckets, folders, and objects is as follows:
package com.chapter3; import java.util.List; import com.amazonaws.services.s3.model.DeleteObjectRequest; import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.S3ObjectSummary; public class DeleteOperations extends AmazonS3ClientInitializer{ public...