本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
S3使用创建存储桶策略以部署静态网站 AWS SDKs
您可以使用将静态网站从 Amazon S3 部署 AWS SDKs 到 Amplify Hosting。如果您使用软件开发工具包部署网站,则必须创建自己的存储桶策略,以授予 Amplify Hosting 检索S3 存储桶中对象的权限。
有关如何创建存储桶策略的更多信息,请参阅《Amazon Simple Storage Service 用户指南》中的适用于 Amazon S3 的存储桶策略。
以下示例存储桶策略授予 Amplify Hosting 列出存储分区和检索指定的 AWS 账户 Amplify 应用程序 ID 和分支的存储桶对象的权限。
要使用此示例,请执行以下操作:
amzn-s3-demo-website-bucket/prefix
替换为您网站存储桶的名称和前缀。
111122223333
用你的 AWS 账户 身份证替换。
region-id
替换为 Amplify 应用程序所在的,例如。 AWS 区域 us-east-1
app_id
用你的 Amplify 应用程序 ID 替换。可在 Amplify 控制台中获得此信息。
branch_name
替换为您的分支名称。
在您的存储桶策略中,aws:SourceArn
必须是经过 URL 编码(百分比编码)的分支 ARN。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAmplifyToListPrefix_appid_branch_prefix_",
"Effect": "Allow",
"Principal": {
"Service": "amplify.amazonaws.com"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::amzn-s3-demo-website-bucket/prefix
/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "111122223333
",
"aws:SourceArn": "arn%3Aaws%3Aamplify%3Aregion-id
%3A111122223333
%3Aapps%2Fapp_id
%2Fbranches%2Fbranch_name
",
"s3:prefix": ""
}
}
},
{
"Sid": "AllowAmplifyToReadPrefix__appid_branch_prefix_",
"Effect": "Allow",
"Principal": {
"Service": "amplify.amazonaws.com"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::amzn-s3-demo-website-bucket/prefix
/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "111122223333
",
"aws:SourceArn": "arn%3Aaws%3Aamplify%3Aregion-id
%3A111122223333
%3Aapps%2Fapp_id
%2Fbranches%2Fbranch_name
"
}
}
},
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::amzn-s3-demo-website-bucket
/*",
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}