S3对公网开放,解决权限问题
1、进入存储桶,点击权限,定位到“阻止公有访问(存储桶设置)”,全部不勾选
2、定位到“存储桶策略” 编辑更改内容
(公开)
{
"Version": "2008-10-17",
"Id": "Policy1380877762691",
"Statement": [
{
"Sid": "Stmt1380877761162",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::存储桶名称/*"
}
]
}
(可以是公有的)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DelegateS3Access",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::角色自己定义:user/s3tos3"
},
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::存储桶名称/*",
"arn:aws:s3:::存储桶名称"
]
}
]
3、解决跨域问题
定位到“跨源资源共享(CORS)”,编辑内容
相关亚马逊文档:亚马逊S3跨域配置文档
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"请求方的域名地址,也可以配置成所有--*"
],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2"
],
"MaxAgeSeconds": 3000
}
]
补:如果不是对公网开放的存储桶策略格式可以是如下文章来源:https://www.toymoban.com/news/detail-507448.html
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DelegateS3Access",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::账号id:user/s3tos3"
},
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::存储桶名称/*",
"arn:aws:s3:::存储桶名称"
]
}
]
}
配置对公网开放的配置文章来源地址https://www.toymoban.com/news/detail-507448.html
{
"Version": "2008-10-17",
"Id": "Policy1380877762691",
"Statement": [
{
"Sid": "Stmt1380877761162",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::存储桶名称/*"
}
]
}
到了这里,关于亚马逊S3解决跨域和权限问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!