ListObjectsV2访问被拒绝 Java SDK

huangapple go评论64阅读模式
英文:

ListObjectsV2 access denied Java SDK

问题

我正在尝试使用以下 Java 代码列出指定前缀下存储桶中的所有对象

ListObjectsV2Request request =
      new ListObjectsV2Request()
          .withBucketName(bucketName)
          .withDelimiter("/")
          .withPrefix(prefix)
          .withMaxKeys(2);
ListObjectsV2Result result;
do {
  result = s3Client.listObjectsV2(req);
  log.info("结果大小为:" + result.getObjectSummaries().size());

s3Client 已正确设置,因为我可以进行上传、删除等操作。我只在列出对象时遇到问题。如果不提供前缀,我会收到访问被拒绝的错误;但如果提供前缀,我会收到空响应。我使用了 aws s3 ls 进行了权限测试,能够打印出整个存储桶的内容。有关调试的下一步想法吗?


<details>
<summary>英文:</summary>

I&#39;m trying to list all objects in a bucket under a prefix with the following code in java:

    ListObjectsV2Request request =
          new ListObjectsV2Request()
              .withBucketName(bucketName)
              .withDelimiter(&quot;/&quot;)
              .withPrefix(prefix)
              .withMaxKeys(2);
      ListObjectsV2Result result;
      do {
        result = s3Client.listObjectsV2(req);
        log.info(&quot;Results size is : &quot; + result.getObjectSummaries().size());

The s3client is set up correctly because I can upload, delete, etc. I only have a problem listing objects. I receive access denied if I don&#39;t provide a prefix, but if I provide a prefix I receive an empty response. I tested `aws s3 ls` to see if I had permissions and I&#39;m able to print the whole bucket out that way. Any ideas for next steps for debugging?

</details>


# 答案1
**得分**: 0

通过ssh登录到实例并比较aws s3 ls和s3api的输出进行了解决。忘记了必需的前缀和分隔符。

<details>
<summary>英文:</summary>

Solved by sshing into instance and comparing the output of aws s3 ls &amp; s3api. Had forgotten mandatory prefix and delimiter.

</details>



huangapple
  • 本文由 发表于 2020年10月23日 01:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/64487098.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定