这就是我们制作 S3 Bucket 对象列表请求的方式。
final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(bucketName)
假设我们已将内联策略附加到请求资源的用户,
{
"Sid": "AllowRootAndHomeListingOfBucket",
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::XXXX.XXXX",
"arn:aws:s3:::XXXX.XXXXX/php_serialize.rb"
]
},
{
"Sid": "AllowAllS3ActionsInUserFolder",
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::XXXX.XXXX/php_serialize.rb"
]
}
此策略的效果是,它允许用户列出所有根级别对象,包括授予用户权限的资源。
do {
result = s3client.listObjectsV2(req);
for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
}
System.out.println("Next Continuation Token : " + result.getNextContinuationToken());
req.setContinuationToken(result.getNextContinuationToken());
} while(result.isTruncated() == true );
结果是:
text.rb
test/abc
php_serialize.rb
xyx/test.txt
我只想让php_serialize.rb
, 列出。如果请求用户不知道前缀,他被授予权限。
按照请求,在这种情况下将不起作用。
final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(bucketName).withPrefix("php_serialize.rb");