【问题标题】:aws policy for read/write to a file within a bucket用于读取/写入存储桶中文件的 aws 策略
【发布时间】:2017-03-05 07:01:00
【问题描述】:

我有以下 s3 结构:

存储桶名称:测试存储桶

文件:test.json

我有以下 aws 政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Action": "s3:GetObject",
            "Action": "s3:DeleteObject",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::test-bucket"
        }
    ]
}

此策略附加到访问密钥为 123 的用户。

当我尝试使用 sdk 将 test.json 放入或获取 test-bucket 时:

BasicAWSCredentials awsCreds = new BasicAWSCredentials("123", "secretKeyId");
s3Client = AmazonS3ClientBuilder.standard()
                        .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                        .withRegion("US-EAST-1")
                        .build();
s3Client.putObject(new PutObjectRequest("test-bucket", "test.json", file));

这将导致访问拒绝问题。

如果我将政策的资源更改为

 "Resource": "*"

然后它会工作。我只是想确保我放置的资源格式正确。出了什么问题?

【问题讨论】:

  • 错字:ListBucekt -> ListBucket
  • @Jeremy 哦,那是复制粘贴过程中的错字。

标签: java amazon-web-services amazon-s3 aws-sdk


【解决方案1】:

您需要让亚马逊知道,除了您的存储桶之外,您还想访问存储桶的内容。

所以从以下位置更改资源:

"Resource": "arn:aws:s3:::test-bucket"

类似于:

"Resource": [
    "arn:aws:s3:::test-bucket",
    "arn:aws:s3:::test-bucket/*"
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多