Delete operations

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; ...

Get Amazon S3 Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.