Java – Delete a bucket on S3

In this post we will provide a code sample of how to delete a bucket on S3 (amazon web services).

Setup:

You will need to add the following dependency to your project.

You will also need to setup your AWS credentials a simple approach is to export the following environment variables:

  • AWS_REGION=<your-aws-region>
  • AWS_ACCESS_KEY_ID=<your-access-key>
  • AWS_SECRET_ACCESS_KEY=<your-secret-access-key>

For alternative approaches please check reference below for more details.

Delete a bucket in S3:

The following example shows how to delete a bucket named ‘your-bucket-name’.

Running the above code will remove the bucket as long as you have your AWS credentials setup correctly on your machine, as well as you having the correct permissions to delete that bucket.

In conclusion I hope you found this post useful and it helps you understand how to delete a bucket on S3.

Similar posts:

  1. Get a file from S3
  2. List all files in a S3 bucket
  3. How to convert an InputStream to a FIle

References:

  1. AWS credentials setup
  2. What is Amazon S3

Leave a Reply

Your email address will not be published. Required fields are marked *