Java Code Examples for com.amazonaws.services.s3.AmazonS3.doesBucketExistV2()

The following are Jave code examples for showing how to use doesBucketExistV2() of the com.amazonaws.services.s3.AmazonS3 class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ats-framework   File: S3Operations.java   View Source Code Vote up 5 votes
/**
 * Check bucket for existence
 *
 * @param bucketName the bucket name
 */
@PublicAtsApi
public boolean doesBucketExist( String bucketName ) {

    AmazonS3 s3Client = getClient();
    return s3Client.doesBucketExistV2(bucketName);
}
 
Example 2
Project: alfresco-lambda-java-utils   File: S3Cleaner.java   View Source Code Vote up 5 votes
/**
 * Empties the contents of the given bucket and optionally deletes the bucket
 * 
 * @param s3 The S3 client object to use
 * @param bucketName The bucket to empty
 * @param deleteBucket Flag to determine whether to delete the bucket after emptying
 * @param context Lambda context object
 */
public static void emptyBucket(AmazonS3 s3, String bucketName, boolean deleteBucket, Context context)
{
    if (s3.doesBucketExistV2(bucketName))
    {
        logDebug("Emptying bucket '" + bucketName + "'...", context);
        
        VersionListing versionListing = s3.listVersions(new ListVersionsRequest().withBucketName(bucketName));
        while (true) 
        {
            for (S3VersionSummary vs : versionListing.getVersionSummaries()) 
            {
                s3.deleteVersion(bucketName, vs.getKey(), vs.getVersionId());
            }
            
            if (versionListing.isTruncated()) 
            {
                logDebug("Fetching next batch of versions for bucket '" + bucketName + "'", context);
                versionListing = s3.listNextBatchOfVersions(versionListing);
            } 
            else 
            {
                break;
            }
        }
        
        logInfo("Successfully emptied bucket '" + bucketName + "'", context);
        
        if (deleteBucket)
        {
            logDebug("Deleting bucket '" + bucketName + "'...", context);
            s3.deleteBucket(bucketName);
            logInfo("Successfully deleted bucket '" + bucketName + "'", context);
        }
    }
    else
    {
        logWarn("Bucket '" + bucketName + "' does not exist", context);
    }
}