如果 Amazon S3 存储桶应该在整个 AWS 云中"globally unique",我如何拥有一个名为 "todo" 的存储桶?



我在Amazon S3中创建了一个桶,并将其命名为"todo",桶被成功创建,没有错误。绝对不可能没有其他人使用过这个桶名,所以如果桶应该是全局唯一的,这是怎么发生的?

我尝试创建一个名为todo的桶结果得到了一个异常。我猜你是第一个用这个名字命名一个桶的人。

public static void main(String[] args) throws URISyntaxException {
final String USAGE = "n" +
"Usage:n" +
"    <bucketName> nn" +
"Where:n" +
"    bucketName - the name of the bucket to create. The bucket name must be unique, or an error occurs.nn" ;
//  if (args.length != 1) {
//      System.out.println(USAGE);
//      System.exit(1);
// }
String bucketName = "todo"; //args[0];
System.out.format("Creating a bucket named %sn",
bucketName);
Region region = Region.US_EAST_1;
S3Client s3 = S3Client.builder()
.region(region)
.build();
createBucket (s3, bucketName);
s3.close();
}
// 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);
}
}

相关内容

  • 没有找到相关文章

最新更新