如何指定S3存储桶区域

时间:2019-08-06 17:05:38

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

我在网上看过,我们有一个名称为s3的存储桶:

private void fetchPhotos() {
    Task<Photo> task = null;
    List<Photo> photos = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        if (task == null) {
            task = getPhoto(i);
        } else {
            final int pos = i;
            task = task.onSuccessTask(photo -> {
                photos.add(photo);
                return getPhoto(pos);
            });
        }
    }

    task.addOnCompleteListener((photoTask) -> {
        photos.add(photoTask.getResult()); //Adding the final result.
        for (int i = 0; i < photos.size(); i++) {
            Log.i("DEMO", photos.get(i).toString());
        }
    });
}

private Task<Photo> getPhoto(int i) {
    Task<Photo> task = Tasks.call(Executors.newSingleThreadExecutor() /*You can specify the threading here*/, () -> new Photo(i) /*Your logic to fetch photo goes here...*/);
    return task;
}

class Photo {

    int pos = 0;

    Photo(int p) {
        this.pos = p;
    }

    @Override
    public String toString() {
        return String.valueOf(pos);
    }
}

所以据说这是网址

nixos-build

但是我们不必指定AWS区域吗?我们如何将其放在URL中?

3 个答案:

答案 0 :(得分:2)

存储桶名称的格式为:

http://BUCKETNAME.s3-REGION.amazonaws.com

示例:

http://mybucket.s3-ap-southeast-2.amazonaws.com
http://my.bucket.name.has.dots.s3-us-west-2.amazonaws.com
http://invoices.s3.amazonaws.com   (Defaults to us-east-1, can involve redirects to other regions)

请注意存储区名称和s3-REGION部分中的破折号之后的句点。

还有一种较旧的格式:

http://s3-ap-southeast-2.amazonaws.com/mybucket

但是,该格式已被弃用。参见:Amazon S3 Path Deprecation Plan – The Rest of the Story | AWS News Blog

答案 1 :(得分:0)

答案 2 :(得分:0)