Search in sources :

Example 1 with HeadBucketRequest

use of software.amazon.awssdk.services.s3.model.HeadBucketRequest in project aws-doc-sdk-examples by awsdocs.

the class MovieLensDatasetProvider method createBucket.

// Create a bucket by using a S3Waiter object
public static void createBucket(S3Client s3Client, String bucketName) {
    try {
        S3Waiter s3Waiter = s3Client.waiter();
        CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).build();
        s3Client.createBucket(bucketRequest);
        HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
        // Wait until the bucket is created and print out the response
        WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
        waiterResponse.matched().response().ifPresent(System.out::println);
        System.out.println(bucketName + " is ready");
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : HeadBucketRequest(software.amazon.awssdk.services.s3.model.HeadBucketRequest) CreateBucketRequest(software.amazon.awssdk.services.s3.model.CreateBucketRequest) HeadBucketResponse(software.amazon.awssdk.services.s3.model.HeadBucketResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) S3Waiter(software.amazon.awssdk.services.s3.waiters.S3Waiter)

Example 2 with HeadBucketRequest

use of software.amazon.awssdk.services.s3.model.HeadBucketRequest in project aws-doc-sdk-examples by awsdocs.

the class S3ObjectOperations method createBucket.

// Create a bucket by using a S3Waiter object
public static void createBucket(S3Client s3Client, String bucketName, Region region) {
    S3Waiter s3Waiter = s3Client.waiter();
    try {
        CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).createBucketConfiguration(CreateBucketConfiguration.builder().locationConstraint(region.id()).build()).build();
        s3Client.createBucket(bucketRequest);
        HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
        // Wait until the bucket is created and print out the response
        WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
        waiterResponse.matched().response().ifPresent(System.out::println);
        System.out.println(bucketName + " is ready");
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : HeadBucketRequest(software.amazon.awssdk.services.s3.model.HeadBucketRequest) CreateBucketRequest(software.amazon.awssdk.services.s3.model.CreateBucketRequest) HeadBucketResponse(software.amazon.awssdk.services.s3.model.HeadBucketResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) S3Waiter(software.amazon.awssdk.services.s3.waiters.S3Waiter)

Example 3 with HeadBucketRequest

use of software.amazon.awssdk.services.s3.model.HeadBucketRequest in project aws-doc-sdk-examples by awsdocs.

the class S3BucketOps method createBucket.

// snippet-start:[s3.java2.s3_bucket_ops.create_bucket]
// Create a bucket by using a S3Waiter object
public static void createBucket(S3Client s3Client, String bucketName) {
    try {
        S3Waiter s3Waiter = s3Client.waiter();
        CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).build();
        s3Client.createBucket(bucketRequest);
        HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
        // Wait until the bucket is created and print out the response
        WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
        waiterResponse.matched().response().ifPresent(System.out::println);
        System.out.println(bucketName + " is ready");
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : S3Waiter(software.amazon.awssdk.services.s3.waiters.S3Waiter)

Example 4 with HeadBucketRequest

use of software.amazon.awssdk.services.s3.model.HeadBucketRequest in project aws-doc-sdk-examples by awsdocs.

the class S3Scenario method createBucket.

// Create a bucket by using a S3Waiter object
public static void createBucket(S3Client s3Client, String bucketName) {
    try {
        S3Waiter s3Waiter = s3Client.waiter();
        CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).build();
        s3Client.createBucket(bucketRequest);
        HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
        // Wait until the bucket is created and print out the response.
        WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
        waiterResponse.matched().response().ifPresent(System.out::println);
        System.out.println(bucketName + " is ready");
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : S3Waiter(software.amazon.awssdk.services.s3.waiters.S3Waiter)

Example 5 with HeadBucketRequest

use of software.amazon.awssdk.services.s3.model.HeadBucketRequest in project aws-doc-sdk-examples by awsdocs.

the class CreateBucket method createBucket.

// snippet-start:[s3.java2.create_bucket_waiters.main]
public static void createBucket(S3Client s3Client, String bucketName) {
    try {
        S3Waiter s3Waiter = s3Client.waiter();
        CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).build();
        s3Client.createBucket(bucketRequest);
        HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
        // Wait until the bucket is created and print out the response.
        WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
        waiterResponse.matched().response().ifPresent(System.out::println);
        System.out.println(bucketName + " is ready");
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : HeadBucketRequest(software.amazon.awssdk.services.s3.model.HeadBucketRequest) CreateBucketRequest(software.amazon.awssdk.services.s3.model.CreateBucketRequest) HeadBucketResponse(software.amazon.awssdk.services.s3.model.HeadBucketResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) S3Waiter(software.amazon.awssdk.services.s3.waiters.S3Waiter)

Aggregations

S3Waiter (software.amazon.awssdk.services.s3.waiters.S3Waiter)5 CreateBucketRequest (software.amazon.awssdk.services.s3.model.CreateBucketRequest)4 HeadBucketRequest (software.amazon.awssdk.services.s3.model.HeadBucketRequest)4 HeadBucketResponse (software.amazon.awssdk.services.s3.model.HeadBucketResponse)3 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)3 HeadBucketRequest (com.amazonaws.services.s3.model.HeadBucketRequest)1 NoOpWaiterHandler (com.amazonaws.waiters.NoOpWaiterHandler)1 S3AsyncWaiter (software.amazon.awssdk.services.s3.waiters.S3AsyncWaiter)1