Search in sources :

Example 1 with HeadBucketRequest

use of com.amazonaws.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 2 with HeadBucketRequest

use of com.amazonaws.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)

Example 3 with HeadBucketRequest

use of com.amazonaws.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 4 with HeadBucketRequest

use of com.amazonaws.services.s3.model.HeadBucketRequest in project wildfly-camel by wildfly-extras.

the class S3Utils method createBucket.

@SuppressWarnings("unchecked")
public static void createBucket(AmazonS3Client client, String bucketName) throws Exception {
    client.createBucket(bucketName);
    HeadBucketRequest request = new HeadBucketRequest(bucketName);
    Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists();
    Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler());
    future.get(1, TimeUnit.MINUTES);
}
Also used : HeadBucketRequest(com.amazonaws.services.s3.model.HeadBucketRequest) NoOpWaiterHandler(com.amazonaws.waiters.NoOpWaiterHandler)

Example 5 with HeadBucketRequest

use of com.amazonaws.services.s3.model.HeadBucketRequest in project flink by apache.

the class AWSServicesTestUtils method createBucket.

public static void createBucket(S3AsyncClient s3Client, String bucketName) throws ExecutionException, InterruptedException {
    CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).build();
    s3Client.createBucket(bucketRequest);
    HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
    try (final S3AsyncWaiter waiter = s3Client.waiter()) {
        waiter.waitUntilBucketExists(bucketRequestWait).get();
    }
}
Also used : S3AsyncWaiter(software.amazon.awssdk.services.s3.waiters.S3AsyncWaiter) HeadBucketRequest(software.amazon.awssdk.services.s3.model.HeadBucketRequest) CreateBucketRequest(software.amazon.awssdk.services.s3.model.CreateBucketRequest)

Aggregations

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 S3Waiter (software.amazon.awssdk.services.s3.waiters.S3Waiter)3 HeadBucketRequest (com.amazonaws.services.s3.model.HeadBucketRequest)1 NoOpWaiterHandler (com.amazonaws.waiters.NoOpWaiterHandler)1 S3AsyncWaiter (software.amazon.awssdk.services.s3.waiters.S3AsyncWaiter)1