本文整理匯總了Python中troposphere.s3.BucketPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Python s3.BucketPolicy方法的具體用法?Python s3.BucketPolicy怎麽用?Python s3.BucketPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類troposphere.s3
的用法示例。
在下文中一共展示了s3.BucketPolicy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _add_bucket_policy
# 需要導入模塊: from troposphere import s3 [as 別名]
# 或者: from troposphere.s3 import BucketPolicy [as 別名]
def _add_bucket_policy(template, bucket_title, bucket_name):
template.add_resource(s3.BucketPolicy(
"%sPolicy" % bucket_title,
Bucket=bucket_name,
PolicyDocument={
"Version": "2012-10-17",
"Statement": [{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource":[
"arn:aws:s3:::%s/*" % bucket_name
]
}]
}
))
示例2: add_bucket
# 需要導入模塊: from troposphere import s3 [as 別名]
# 或者: from troposphere.s3 import BucketPolicy [as 別名]
def add_bucket(self, name, access_control, static_site, route53, public_hosted_zone):
"""
Helper method creates a directory service resource
@param name [string] Fully qualified name for the bucket
(corp.example.com)
@param access_control [string] type of access control for the bucket
@param static_site [boolean] should the bucket host a static site
@param route53 [boolean] create a route53 entry?
"""
if route53:
self.add_dns_alias(
name,
"s3-website-us-east-1.amazonaws.com",
"Z3AQBSTGFYJSTF",
public_hosted_zone
)
if access_control == "PublicRead":
policy = s3.BucketPolicy(
name.replace('.', '') + "BucketPolicy",
Bucket=name,
PolicyDocument={
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::%s/*" % name
}
]
}
)
self.add_resource(policy)
bucket = s3.Bucket(
name.replace('.', '') + "Bucket",
BucketName=name,
AccessControl=access_control,
)
if static_site:
web_config = s3.WebsiteConfiguration(IndexDocument='index.html')
bucket.properties['WebsiteConfiguration'] = web_config
return self.add_resource(bucket)