amazon-web-services - AWS S3 上传失败,ACL public-true
问题描述
我在 Ruby 中有这个简单的脚本来上传我从 AWS 文档中获得的 S3 上的文件:
def object_uploaded?(s3_resource, bucket_name, object_key, file_path)
object = s3_resource.bucket(bucket_name).object(object_key)
File.open(file_path, 'rb') do |file|
object.put(body: file, acl: 'public-read')
end
return true
rescue StandardError => e
puts "Error uploading object: #{e.message}"
return false
end
当我添加acl: 'public-read'时,该脚本会拒绝访问。如果我删除它,效果很好。
这是我的存储桶策略:
{
"Version": "2012-10-17",
"Id": "Policy1610635552932",
"Statement": [
{
"Sid": "Stmt1610635551842",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::[mybucket]/*"
}
]
}
这是我的 IAM 政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:ListStorageLensConfigurations",
"s3:GetAccessPoint",
"s3:PutAccountPublicAccessBlock",
"s3:GetAccountPublicAccessBlock",
"s3:ListAllMyBuckets",
"s3:ListAccessPoints",
"s3:ListJobs",
"s3:PutStorageLensConfiguration",
"s3:CreateJob"
],
"Resource": "*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::[mybucket]",
"arn:aws:s3:::[mybucket]/*"
]
}
]
}
有什么方法可以按照 AWS 的建议打开阻止公共访问并通过设置 acl 来获得公共可访问的文件?我的政策有什么问题?
解决方案
如果存储桶的阻止公共访问设置已打开,您将无法上传具有 ACL 公开读取的文件。根据文档:“Amazon S3 阻止公共访问阻止应用任何允许对 S3 存储桶中的数据进行公共访问的设置。” (https://docs.aws.amazon.com/AmazonS3/latest/user-guide/block-public-access.html)
推荐阅读
- laravel-cashier - 同时启动多个(许多)Stripe Checkout 会话?
- json - Flutter json 对象 - 类型 _InternalLinkedHashMap
不是 List 类型的子类型 - excel - 如何在 iPad 上运行 Excel 宏?
- javascript - 如何使用 react 和 yup 验证动态字段名称
- javascript - 如何滚动到 ReactJs 中的元素?
- python - Pyodbc,如何从 SQL Server 存储过程中获取结果
- android - “:”在android项目依赖项的树视图中是什么意思?
- javascript - 如何在 Array.map()、REACT.JS 中操作一个元素而不影响其他元素
- python - 关于 pymc3、arviz 和 theano 包的稳定版本是什么?
- python - Python:scipy.optimize,bisection 可以使用返回多个值的函数 f 吗?