第三方以编程方式拥有的Amazon S3存储桶访问 [英] Amazon S3 bucket access programmatically owned by third party

查看:96
本文介绍了第三方以编程方式拥有的Amazon S3存储桶访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是S3的新手.我们的供应商之一正在与我们共享存储桶和对象.我们创建了一个AWS账户,并将团队成员添加为用户.我们可以通过Amazon AWS CLI访问存储桶中的数据.我正在寻找Java api以编程方式访问数据.

I am new to S3. One of our vendor is sharing a bucket and objects with us. We created an AWS account and added our team members as users. We can access data in the bucket via amazon aws cli. I am looking for java api to access data programatically.

我创建了一个独立代码

    /*
     * Create your credentials file at ~/.aws/credentials (C:\Users\USER_NAME\.aws\credentials for Windows users) 
     * and save the following lines after replacing the underlined values with your own.
     *
     * [default]
     * aws_access_key_id = YOUR_ACCESS_KEY_ID
     * aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
     */

    AmazonS3 s3 = new AmazonS3Client();
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    s3.setRegion(usEast1); 
    System.out.println("Listing objects");
        ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
                .withBucketName("exports.abx.t-z/xyz")
                );
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            System.out.println(" - " + objectSummary.getKey() + "  " +
                    "(size = " + objectSummary.getSize() + ")");
        }
        System.out.println();

现在我正在跟踪异常

    Listing objects
Caught an AmazonServiceException, which means your request made it to Amazon S3, but was rejected with an error response for some reason.
Error Message:    The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey; Request ID: C80B0460828347D0)
HTTP Status Code: 404
AWS Error Code:   NoSuchKey
Error Type:       Client
Request ID:       C80B0460828347D0

我没有访问密钥.感谢您的帮助.

I do not have the key to access. Any help is appreciated.

谢谢, 阿米特(Amit)

Thanks, Amit

推荐答案

404响应表明您的凭据还可以,但是您要求的内容不存在.

The 404 response indicates that your credentials are ok, but the thing you asked for does not exist.

这部分代码看起来可疑:

This part of the code looks suspicious:

new ListObjectsRequest().withBucketName("exports.abx.t-z/xyz")

应为withBucketName方法指定存储桶名称.我怀疑在您的情况下,存储桶名称应该只是"exports.abx.t-z".如果要列出该存储桶中"xyz",文件夹"中的所有对象,则需要执行以下操作:

The withBucketName method should be given the bucket name. I suspect that in your case, the bucket name should be simply "exports.abx.t-z". If you are looking to list all the objects in the "xyz" "folder" within that bucket, then you would want to do something like this:

new ListObjectsRequest().withBucketName("exports.abx.t-z").withPrefix("xyz")

这篇关于第三方以编程方式拥有的Amazon S3存储桶访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆