简体   繁体   English

AWS S3请求者付款不适用于TransferManager

[英]AWS S3 Requester Pays Does not work with TransferManager

I am trying to use TransferManager class in my java program to download a file from a Requester Pays Buckets . 我正在尝试在Java程序中使用TransferManager类从“ 请求者付款存储桶”下载文件。 I am getting "Status Code: 403" exception from amazon AWS. 我从亚马逊AWS收到“状态代码:403”异常。 I wrote a simple program to test this feature and compare it single connection way of downloading a file. 我编写了一个简单的程序来测试此功能,并比较下载文件的单连接方式。 Here is my code: 这是我的代码:

import java.io.*;
import com.amazonaws.auth.*;
import com.amazonaws.services.s3.*;
import com.amazonaws.services.s3.model.*;
import com.amazonaws.services.s3.transfer.*;
import com.amazonaws.util.IOUtils;
public class RequesterPaysTest {
    final static AWSCredentials awsCredentials = new BasicAWSCredentials(MY IAMAccessKey,MY IAMSecretKey);
    final static String bucketName = "7268982505fe.mixnode.com";
    final static String fileName = "5379-7268982505fe-0-1496081968663.warc.gz";
    final static AWSCredentialsProvider awsCredentialsProvider =  new AWSStaticCredentialsProvider(awsCredentials);
    final static AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider).withRegion(MY bucketRegion).build();
    final static GetObjectRequest getRequest = new GetObjectRequest(bucketName, fileName, true);

    static void testSimpleRequesterPays() {
        try {
        S3Object object = s3client.getObject(getRequest);
        InputStream objectData = object.getObjectContent();
        FileOutputStream out = new FileOutputStream (new File(fileName));
        IOUtils.copy(objectData, out);
        out.close();
        System.out.println(" Simple RequesterPays successful");
        } catch (Exception e) {
        System.out.println(" Simple RequesterPays unsuccessful: " + e.getMessage());
        }
    }
    static void testTransferManagerRequesterPays() {
        try {
            TransferManager tx = TransferManagerBuilder.standard().withS3Client(s3client).build();
            Download download = tx.download(getRequest, new File(fileName));
            while (download.isDone() == false)
                Thread.sleep(10);
            System.out.println(" TransferManager RequesterPays successful");
        } catch (Exception e) {
        System.out.println(" TransferManager RequesterPays unsuccessful: " + e.getMessage());
        }
    }
public static void main(String[] args) throws IOException {
    testSimpleRequesterPays();
    testTransferManagerRequesterPays();
}
}

And here is the output: 这是输出:

Simple RequesterPays successful
 TransferManager RequesterPays unsuccessful: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: 77D5EBF5EE195A7A)

As you can see, the same file can be downloaded using simple method but not with TransferManager. 如您所见,可以使用简单方法下载相同文件,但不能使用TransferManager下载相同文件。 I tried to create my own bucket and played around with permissions but it did not work. 我尝试创建自己的存储桶并使用权限进行操作,但没有成功。 I was wondering if I miss anything in my code? 我想知道我的代码中是否错过任何内容? Or whether AWS s3 does not have support for using TransferManager on a requester pays bucket? 还是AWS s3不支持在请求者付费存储桶上使用TransferManager?

TransferManager internally using http HEAD method instead of GET for downloading objects(file(s)). 内部使用HTTP HEAD方法而不是GET的 TransferManager来下载对象(文件)。 You can find it by debugging TransferManager SDK code. 您可以通过调试TransferManager SDK代码找到它。 If you don't have HEAD method configuration in your aws api gateway, you have to create HEAD method configuration to match with TransferManager SDK code. 如果aws api网关中没有HEAD方法配置,则必须创建HEAD方法配置以与TransferManager SDK代码匹配。 By the way if resource not found it should give 404 but you are getting 403. reason is here https://forums.aws.amazon.com/thread.jspa?threadID=216684 顺便说一句,如果找不到资源,它应该给出404,但是您得到403。原因在这里https://forums.aws.amazon.com/thread.jspa?threadID=216684

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS SDK for S3中的TransferManager是否正在执行异步I / O? - Is the TransferManager in AWS SDK for S3 doing Asynchronous I/O? AWS TransferManager uploadFileList 在 S3 中截断文件名 - AWS TransferManager uploadFileList truncating file name in S3 对象传输完成后,AWS S3 TransferManager不会退出 - AWS S3 TransferManager doesn't exit upon completion of object transfer 使用 AWS Java S3 SDK TransferManager 从 SFTP 流恢复上传 - Using AWS Java S3 SDK TransferManager to resume an upload from a SFTP stream AWS S3 下载暂停方法无法正常工作 - AWS S3 Download Pause Method Does Not Work Properly 我们可以使用相同的 AWS S3 TransferManager 实例,还是应该为每个文件上传创建一个新实例? - Can we use the same instance of AWS S3 TransferManager or should we create a new instance for each file upload? Java中使用TransferManager上传目录到s3无一例外失败 - Use TransferManager to upload directory to s3 in Java failed without exception S3-TransferManager获取num个正在进行的上传,已完成且失败 - S3 - TransferManager get num uploads in progress, complete and failed 部署到EBS时,AWS S3上传图像不起作用,但在localhost SpringBoot(JAVA)中起作用 - AWS S3 uploading Images does not work when deployed to EBS but works in localhost SpringBoot (JAVA) 使用java通过TransferManager在S3上上传文件时如何使文件权限“公开”? - How to make file permission "read public" while uploading file on S3 by TransferManager using java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM