當前位置: 首頁>>代碼示例>>Java>>正文


Java CreateBucketConfiguration類代碼示例

本文整理匯總了Java中software.amazon.awssdk.services.s3.model.CreateBucketConfiguration的典型用法代碼示例。如果您正苦於以下問題:Java CreateBucketConfiguration類的具體用法?Java CreateBucketConfiguration怎麽用?Java CreateBucketConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CreateBucketConfiguration類屬於software.amazon.awssdk.services.s3.model包,在下文中一共展示了CreateBucketConfiguration類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: modifyRequest_UpdatesLocationConstraint_When_NullLocationConstraint

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
@Test
public void modifyRequest_UpdatesLocationConstraint_When_NullLocationConstraint() {
    CreateBucketRequest request = CreateBucketRequest.builder()
                                                     .bucket("test-bucket")
                                                     .createBucketConfiguration(CreateBucketConfiguration.builder()
                                                                                                         .build())
                                                     .build();

    Context.ModifyRequest context = () -> request;
    ExecutionAttributes attributes = new ExecutionAttributes()
            .putAttribute(AwsExecutionAttributes.AWS_REGION, Region.US_WEST_2);

    SdkRequest modifiedRequest = new CreateBucketInterceptor().modifyRequest(context, attributes);
    String locationConstraint = ((CreateBucketRequest) modifiedRequest).createBucketConfiguration().locationConstraintString();

    assertThat(locationConstraint).isEqualToIgnoringCase("us-west-2");
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:18,代碼來源:CreateBucketInterceptorTest.java

示例2: modifyRequest_UsEast1_UsesNullBucketConfiguration

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
/**
 * For us-east-1 there must not be a location constraint (or containing CreateBucketConfiguration) sent.
 */
@Test
public void modifyRequest_UsEast1_UsesNullBucketConfiguration() {
    CreateBucketRequest request = CreateBucketRequest.builder()
                                                     .bucket("test-bucket")
                                                     .createBucketConfiguration(CreateBucketConfiguration.builder()
                                                                                                         .build())
                                                     .build();

    Context.ModifyRequest context = () -> request;
    ExecutionAttributes attributes = new ExecutionAttributes()
            .putAttribute(AwsExecutionAttributes.AWS_REGION, Region.US_EAST_1);

    SdkRequest modifiedRequest = new CreateBucketInterceptor().modifyRequest(context, attributes);
    assertThat(((CreateBucketRequest) modifiedRequest).createBucketConfiguration()).isNull();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:19,代碼來源:CreateBucketInterceptorTest.java

示例3: main

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
public static void main(String[] args) {

        Region region = Region.US_WEST_2;
        S3Client s3 = S3Client.builder().region(region).build();
        String bucket = "bucket" + System.currentTimeMillis();

        // Create bucket
        CreateBucketRequest createBucketRequest = CreateBucketRequest
                .builder()
                .bucket(bucket)
                .createBucketConfiguration(CreateBucketConfiguration.builder()
                                                                    .locationConstraint(region.value())
                                                                    .build())
                .build();
        s3.createBucket(createBucketRequest);

        // List buckets
        ListBucketsRequest listBucketsRequest = ListBucketsRequest.builder().build();
        ListBucketsResponse listBucketsResponse = s3.listBuckets(listBucketsRequest);
        System.out.println(listBucketsResponse.buckets());

        // Delete empty bucket
        DeleteBucketRequest deleteBucketRequest = DeleteBucketRequest.builder().bucket(bucket).build();
        s3.deleteBucket(deleteBucketRequest);
    }
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:26,代碼來源:S3BucketOps.java

示例4: toLocationConstraint

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
private CreateBucketConfiguration toLocationConstraint(Region region) {
    if (region.equals(Region.US_EAST_1)) {
        // us-east-1 requires no location restraint. See http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUT.html
        return null;
    }
    return CreateBucketConfiguration.builder()
                                    .locationConstraint(region.value())
                                    .build();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:10,代碼來源:CreateBucketInterceptor.java

示例5: setUpFixture

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
@BeforeClass
public static void setUpFixture() throws Exception {
    S3IntegrationTestBase.setUp();
    s3.createBucket(CreateBucketRequest.builder()
                                       .bucket(BUCKET_NAME)
                                       .createBucketConfiguration(CreateBucketConfiguration.builder()
                                                                                           .locationConstraint("us-west-2")
                                                                                           .build())
                                       .build());

    s3.putObject(PutObjectRequest.builder()
                                 .bucket(BUCKET_NAME)
                                 .key(KEY)
                                 .build(), RequestBody.of(new RandomTempFile("foo", 1024)));
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:16,代碼來源:BucketAnalyticsConfigurationIntegrationTest.java

示例6: createBucket

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
private static void createBucket(String bucketName, int retryCount) {
    try {
        s3.createBucket(
                CreateBucketRequest.builder()
                                   .bucket(bucketName)
                                   .createBucketConfiguration(
                                           CreateBucketConfiguration.builder()
                                                                    .locationConstraint(BucketLocationConstraint.US_WEST_2)
                                                                    .build())
                                   .build());
    } catch (S3Exception e) {
        System.err.println("Error attempting to create bucket: " + bucketName);
        if (e.errorCode().equals("BucketAlreadyOwnedByYou")) {
            System.err.printf("%s bucket already exists, likely leaked by a previous run\n", bucketName);
        } else if (e.errorCode().equals("TooManyBuckets")) {
            System.err.println("Printing all buckets for debug:");
            s3.listBuckets().buckets().forEach(System.err::println);
            if (retryCount < 2) {
                System.err.println("Retrying...");
                createBucket(bucketName, retryCount + 1);
            } else {
                throw e;
            }
        } else {
            throw e;
        }
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:29,代碼來源:S3IntegrationTestBase.java

示例7: setUp

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws IOException {
    IntegrationTestBase.setUp();
    s3.createBucket(CreateBucketRequest.builder()
                                       .bucket(BUCKET_NAME)
                                       .createBucketConfiguration(
                                               CreateBucketConfiguration.builder()
                                                                        .locationConstraint(region.value())
                                                                        .build())
                                       .build());
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:12,代碼來源:CloudTrailIntegrationTest.java

示例8: createBucket

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
/**
 * Creates a bucket and waits for it to exist.
 *
 * @param s3         The AmazonS# client to use.
 * @param bucketName The name of the bucket to create.
 */
protected static void createBucket(S3Client s3, String bucketName, String region) throws InterruptedException {
    s3.createBucket(CreateBucketRequest.builder()
                                       .bucket(bucketName)
                                       .createBucketConfiguration(CreateBucketConfiguration.builder()
                                                                                           .locationConstraint(region)
                                                                                           .build())
                                       .build());

    Thread.sleep(1000);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:17,代碼來源:DynamoDBS3IntegrationTestBase.java

示例9: createBucket

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
private static void createBucket(String bucket, Region region) {
    // Create bucket
    s3.createBucket(CreateBucketRequest
                            .builder()
                            .bucket(bucket)
                            .createBucketConfiguration(
                                    CreateBucketConfiguration.builder()
                                                             .locationConstraint(region.value())
                                                             .build())
                            .build());
}
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:12,代碼來源:S3BucketDeletion.java

示例10: createBucket

import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration; //導入依賴的package包/類
private static void createBucket(String bucket, Region region) {
    s3.createBucket(CreateBucketRequest
                            .builder()
                            .bucket(bucket)
                            .createBucketConfiguration(
                                    CreateBucketConfiguration.builder()
                                                             .locationConstraint(region.value())
                                                             .build())
                            .build());
}
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:11,代碼來源:S3ObjectOperations.java


注:本文中的software.amazon.awssdk.services.s3.model.CreateBucketConfiguration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。