Java – Create a bucket in S3

In this post we will provide a code sample of how to create a bucket in S3 (amazon web services). In order to create a bucket you need to ensure that you have setup the appropriate security access, you can find more information regarding this in the reference section.

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 the reference section below for more details

Delete a bucket in S3:

The following code example show how to delete a bucket using the amazon java sdk.

Running the above code will create a bucket in S3. You will need to have setup your development environment correctly to ensure you have enough access to create a bucket on S3. Please check the references for more details about this.

In conclusion, I hope you found this post useful and helps you understand how to work with AWS S3.

Similar posts:

  1. Get file in a AWS S3 bucket
  2. List files in a S3 Bucket
  3. Java HttpClient GET request example
  4. Setup logging with MDC

References:

  1. AWS S3 documentation
  2. Working with AWS credentials

Leave a Reply

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