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

时间:2017-07-17 21:55:57

标签: java amazon-web-services amazon-s3

我正在尝试使用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是有效的枚举常量。有些人可以让我知道我在这里失踪了什么。

1 个答案:

答案 0 :(得分:1)

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