gpt4 book ai didi

java - 无法在特定区域创建 S3 存储桶

转载 作者:行者123 更新时间:2023-11-30 06:36:26 29 4
gpt4 key购买 nike

我正在尝试使用 AWS Java API 创建存储桶,但无法在除 US_WEST_1 之外的任何区域中创建。

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CreateBucketRequest;
import com.amazonaws.services.s3.model.GetBucketLocationRequest;

public class CreateBucket {
private static String bucketName = "hellobucket6434";

public static void main(String[] args) throws IOException {
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
s3client.setRegion(Region.getRegion(Regions.AP_SOUTH_1));


if(!(s3client.doesBucketExist(bucketName)))
{
// Note that CreateBucketRequest does not specify region. So bucket is
// created in the region specified in the client.
s3client.createBucket(new CreateBucketRequest(
bucketName));
}
// Get location.
String bucketLocation = s3client.getBucketLocation(new GetBucketLocationRequest(bucketName));
System.out.println("bucket location = " + bucketLocation);

}

下面是尝试执行时抛出的错误:

[ERROR] /C:/Users/surya/Desktop/aws-java-sample/src/main/java/com/amazonaws/samp
les/CreateBucket.java:[20,52] cannot find symbol
[ERROR] symbol: variable AP_SOUTH_1
[ERROR] location: class com.amazonaws.regions.Regions

根据 documentation , AP_SOUTH_1 是有效的枚举常量。有人可以让我知道我在这里缺少什么吗?

最佳答案

该区域是在 AWS SDK for Java 1.11.11 中引入的。至少升级到此版本才能使用该区域。注意:最好始终使用最新版本。

关于java - 无法在特定区域创建 S3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45154270/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com