本文整理汇总了Python中troposphere.s3.Bucket方法的典型用法代码示例。如果您正苦于以下问题:Python s3.Bucket方法的具体用法?Python s3.Bucket怎么用?Python s3.Bucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类troposphere.s3
的用法示例。
在下文中一共展示了s3.Bucket方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_bucket_policy
# 需要导入模块: from troposphere import s3 [as 别名]
# 或者: from troposphere.s3 import Bucket [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: render_s3
# 需要导入模块: from troposphere import s3 [as 别名]
# 或者: from troposphere.s3 import Bucket [as 别名]
def render_s3(context, template):
for bucket_name in context['s3']:
props = {
'DeletionPolicy': context['s3'][bucket_name]['deletion-policy'].capitalize(),
'Tags': s3.Tags(**_generic_tags(context, name=False)),
}
bucket_title = _sanitize_title(bucket_name) + "Bucket"
if context['s3'][bucket_name]['cors']:
# generic configuration for allowing read-only access
props['CorsConfiguration'] = s3.CorsConfiguration(
CorsRules=[
s3.CorsRules(
AllowedHeaders=['*'],
AllowedMethods=['GET', 'HEAD'],
AllowedOrigins=['*']
)
]
)
if context['s3'][bucket_name]['website-configuration']:
index_document = context['s3'][bucket_name]['website-configuration'].get('index-document', 'index.html')
props['WebsiteConfiguration'] = s3.WebsiteConfiguration(
IndexDocument=index_document
)
_add_bucket_policy(template, bucket_title, bucket_name)
if context['s3'][bucket_name]['public']:
_add_bucket_policy(template, bucket_title, bucket_name)
props['AccessControl'] = s3.PublicRead
template.add_resource(s3.Bucket(
bucket_title,
BucketName=bucket_name,
**props
))
示例3: add_bucket
# 需要导入模块: from troposphere import s3 [as 别名]
# 或者: from troposphere.s3 import Bucket [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)