public static void main(String[] args) throws Exception { DeleteBucketRequest deleteBucketRequest=new DeleteBucketRequest(AWSResources.S3_BUCKET_NAME); if(AWSResources.S3.doesBucketExist(AWSResources.S3_BUCKET_NAME)) try { AWSResources.S3.deleteBucket(deleteBucketRequest); System.out.println("Bucket Deleted..."); } catch (AmazonS3Exception ex) { if(!ex.getErrorCode().equals("BucketNotEmpty")) throw ex; } //List<KeyVersion> keys = new ArrayList<KeyVersion>(); for(S3ObjectSummary obj : S3Objects.withPrefix(AWSResources.S3, AWSResources.S3_BUCKET_NAME, "")) { // Add the keys to our list of object. AWSResources.S3.deleteObject(AWSResources.S3_BUCKET_NAME, obj.getKey()); } //DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(AWSResources.S3_BUCKET_NAME); //AWSResources.S3.deleteObjects(deleteObjectsRequest); AWSResources.S3.deleteBucket(deleteBucketRequest); if(!AWSResources.S3.doesBucketExist(AWSResources.S3_BUCKET_NAME)) System.out.println("Deleted"); }
@Override public void deleteBucket(DeleteBucketRequest deleteBucketRequest) throws SdkClientException, AmazonServiceException { deleteBucketRequest = beforeClientExecution(deleteBucketRequest); rejectNull(deleteBucketRequest, "The DeleteBucketRequest parameter must be specified when deleting a bucket"); String bucketName = deleteBucketRequest.getBucketName(); rejectNull(bucketName, "The bucket name parameter must be specified when deleting a bucket"); Request<DeleteBucketRequest> request = createRequest(bucketName, null, deleteBucketRequest, HttpMethodName.DELETE); invoke(request, voidResponseHandler, bucketName, null); bucketRegionCache.remove(bucketName); }
public void deleteBucket(String bucketName, boolean recursive) throws AmazonClientException, AmazonServiceException { if(recursive) { deleteKeyWithPrefix(bucketName, ""); } DeleteBucketRequest request = new DeleteBucketRequest(bucketName) ; s3Client.deleteBucket(request); }
@Override public void deleteBucket(DeleteBucketRequest deleteBucketRequest) throws AmazonClientException, AmazonServiceException { delegate.deleteBucket(deleteBucketRequest); }
@Override public void deleteBucket(DeleteBucketRequest deleteBucketRequest) throws AmazonClientException, AmazonServiceException { throw new UnsupportedOperationException(); }
@AfterClass private void cleanUp() throws Exception { DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest(bucketName); s3Client.deleteBucket(deleteBucketRequest); }
@Override public void deleteBucket(String bucketName) throws SdkClientException, AmazonServiceException { deleteBucket(new DeleteBucketRequest(bucketName)); }
@Override public void deleteBucket(DeleteBucketRequest deleteBucketRequest) throws SdkClientException, AmazonServiceException { run(() -> getDelegate().deleteBucket(deleteBucketRequest)); }
@Override public void deleteBucket(DeleteBucketRequest deleteBucketRequest) throws AmazonClientException { }
String deleteBucket(String access_key, String secret_key, String bucket, String endpoint ) { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } message = ("\nDeleting bucket: " + bucket); try { s3Client.deleteBucket(new DeleteBucketRequest(bucket)); } catch (Exception Delete) { if (terminal) { System.out.print("\n\n\n" + Delete.getMessage() + "\n\n\n"); } else { message = message + "\n" + Delete.getMessage(); } } if (message == null) { message = "\nDelete operation failed."; } return message; }
@Override public void deleteBucket(DeleteBucketRequest deleteBucketRequest) throws AmazonClientException, AmazonServiceException { // TODO Auto-generated method stub }
/** * delete bucket * @param region * @param tableName * @throws ConfigException */ public static void deleteBucket(String region, String tableName) throws ConfigException { AmazonS3Client client = getClient(region); client.deleteBucket(new DeleteBucketRequest(tableName)); }