阅读背景:

Amazon AWS SDK转移管理器端点区域

来源:互联网 

I'd like to use the AmazonAWS TransferManager to upload a directory. I successfully create an AmazonS3Client with credentials coming from a TVM.

我想使用amazon . TransferManager来上传一个目录。我成功地创建了一个带有来自TVM的凭据的AmazonS3Client。

When I try to download files with it, it complains:

当我试图用它下载文件时,它会抱怨:

final MultipleFileDownload fileDownloadd=mTransferManager.downloadDirectory(ChanAuth.getBucketName(), remotePath, file);

AWS Error Code: PermanentRedirect, AWS Error Message: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint

AWS错误代码:PermanentRedirect, AWS错误消息:您试图访问的桶必须使用指定的端点进行寻址。请将所有未来的请求发送到此端点

I've read about the subject, and experienced it in the past in other programming languages. I remember it has relation on where you do the final "post" when issuing S3 commands (I had to post directly to my bucket url). But the error comes from deep into the AWS SDK and should be handled there.

我读过这个主题,以前也用过其他编程语言。我记得在发布S3命令时,它与您执行最终“post”的位置有关(我必须直接将其发布到bucket url)。但是错误来自AWS SDK的深层,应该在那里处理。

My buckets are located on the EU-WEST-1 region.

我的桶位于欧盟-西方-1地区。

I initialize the client both with

我都用它初始化客户端

s3Client.setRegion(Regions....(Region.EU_WEST_1))

and

s3Client.setEndpoint("s3-eu-west-1.amazonaws.com");

but I always get TransferManager complaining.

但我总是让转让人抱怨。

I suspect it must be a silly issue, but I'm getting stuck in the million lines and methods of the AwS SDK. There has to be somewhere to set the endpoint correctly or the sdk wouldnt work for buckets outside the US-region.

我怀疑这一定是一个愚蠢的问题,但我被困在AwS SDK的百万行和方法中。必须有正确设置端点的地方,否则sdk不能在美国区域以外的桶上工作。

Help Appreciated :)

帮助感激:)

            06-09 20:16:02.810: D/SynchroService(4408): MESSAGE: nicebeat SYNC
            06-09 20:16:02.810: D/SynchroService(4408): MESSAGE: downlading from chd68f38e7d1360dc1d999354da4f98601/nicebeat/story/sonidonia to /mnt/sdcard/Android/data/com.regaliz.libneo/files/nicebeat/story/sonidonia/lib
            06-09 20:16:02.810: D/SynchroService(4408): is directory? true
            06-09 20:16:03.490: W/System.err(4408): AmazonS3Exception: Status Code: 301, AWS Service: Amazon S3, AWS Request ID: 2695AE32DC39077E, AWS Error Code: PermanentRedirect, AWS Error Message: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint., S3 Extended Request ID: j9zQ8EBzkCGHkRTveri82HoA/Yh9PvJofUPtNJlc9oKrVutG0VjNEGG90WnTGaN4
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:633)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:327)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:179)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2980)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2951)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:479)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.transfer.TransferManager.downloadDirectory(TransferManager.java:588)
            06-09 20:16:03.490: W/System.err(4408):     at com.regaliz.services.Synchro.downloadDirectory(Synchro.java:156)
            06-09 20:16:03.490: W/System.err(4408):     at com.regaliz.services.Synchro.request_commands(Synchro.java:99)
            06-09 20:16:03.490: W/System.err(4408):     at com.regaliz.services.Synchro$3.run(Synchro.java:195)

2 个解决方案

#1


1  

You need to set end points matching with where the buckets are created.

您需要设置与创建桶的位置匹配的端点。

For example : if "mybucket" is created under EU, for the s3client you are creating should be set endpoint as "s3-eu-west-1.amazonaws.com".

例如:如果“mybucket”是在EU下创建的,那么您正在创建的s3client应该设置为“s3- EU -west-1 amazonaws.com”。

Similarly, depending on where your bucket was created, you can setendpoints based on this page : https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

类似地,根据您的bucket创建的位置,您可以根据这个页面设置setendpoints: https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region。

#2


0  

For users from different regions, with different endpoints can refer this: https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

对于来自不同地区的用户,具有不同端点的用户可以参考以下内容:https://docs.aws.amazon.com/general/latest/grde.html #s3_region

If you don't know what exactly your endpoint is you can traverse through all the endpoints and try for each, and zero in on correct endpoint.

如果你不知道你的端点是什么,你可以遍历所有的端点并尝试每一个端点,然后在正确的端点上归零。

private String[] endPoints = new String[] { "s3.amazonaws.com",
            "s3-external-1.amazonaws.com", "s3-us-west-2.amazonaws.com",
            "s3-us-west-1.amazonaws.com", "s3-eu-west-1.amazonaws.com",
            "s3-ap-southeast-1.amazonaws.com",
            "s3-ap-southeast-2.amazonaws.com",
            "s3-ap-northeast-1.amazonaws.com", "s3-sa-east-1.amazonaws.com" };

private int currentIndex = 0;

protected S3TaskResult upload(String filePath) {
        String endPoint = endPoints[currentIndex++];

        S3TaskResult result = new S3TaskResult();

        // Put the image data into S3.
        try {
            // s3Client.createBucket(Constants.getPictureBucket());"

            s3Client.setEndpoint(endPoint);
            // Content type is determined by file extension.
            PutObjectRequest por = new PutObjectRequest(
                    Constants.getPictureBucket(), Constants.PICTURE_NAME,
                    new java.io.File(filePath));
            por.setProgressListener(this);
            s3Client.putObject(por);

            Log.d("S3","SUCCESSFUL ENDPOINT : "+endPoint); // GOT IT!!

        } catch (Exception exception) {
            if (currentIndex < endPoints.length) {
                upload(filePath);

            } 
            exception.printStackTrace();
        }

        return result;
    }

分享到: