本文整理匯總了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");
}
示例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();
}
示例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);
}
示例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();
}
示例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)));
}
示例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;
}
}
}
示例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());
}
示例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);
}
示例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());
}
示例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());
}