AmazonS3Client s3 = new AmazonS3Client();
String bucket_Name = "deleteversions-"+UUID.randomUUID();
//Create a Bucket
s3.createBucket(bucket_Name);
//Enable Versioning
BucketVersioningConfiguration configuration = new BucketVersioningConfiguration(ENABLED);
s3.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket_Name, configuration ));
//Put all the versions
s3.putObject(bucket_Name, "some-key",new ByteArrayInputStream("some-bytes".getBytes()), null);
s3.putObject(bucket_Name, "some-key",new ByteArrayInputStream("other-bytes".getBytes()), null);
//Remove all the versions
for ( S3VersionSummary version : S3Versions.inBucket(s3, bucket_Name) ) {
String key = version.getKey();
String versionId = version.getVersionId();
s3.deleteVersion(bucket_Name, key, versionId);
}
//Remove the bucket
s3.deleteBucket(bucket_Name);
System.out.println("Done!");