本文整理汇总了Python中boto.cloudfront.CloudFrontConnection.get_distribution_info方法的典型用法代码示例。如果您正苦于以下问题:Python CloudFrontConnection.get_distribution_info方法的具体用法?Python CloudFrontConnection.get_distribution_info怎么用?Python CloudFrontConnection.get_distribution_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.cloudfront.CloudFrontConnection
的用法示例。
在下文中一共展示了CloudFrontConnection.get_distribution_info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_distribution
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import get_distribution_info [as 别名]
def create_distribution(access_key_id, secret_access_key, origin, comment="", cnames=None):
import time
from boto.cloudfront import CloudFrontConnection
"""utility function to create a new distribution"""
c = CloudFrontConnection(
access_key_id,
secret_access_key
)
d = c.create_distribution(origin, True, '', cnames, comment)
print """Created distribution
- domain name: %s
- origin: %s
- status: %s
- comment: %s
- id: %s
Over the next few minutes, the distribution will become active. This
function will keep running until that happens.
""" % (d.domain_name, d.config.origin, d.status, d.config.comment, d.id)
# Keep polling CloudFront every 5 seconds until the status changes from
# "InProgress" to (hopefully) "Deployed".
print "\n"
id = d.id
while d.status == "InProgress":
d = c.get_distribution_info(id)
print "."
time.sleep(5)
print "\nThe distribution has been deployed!"
示例2: __init__
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import get_distribution_info [as 别名]
class AmazonCloudFrontDistribution:
"""
Represents a Cloud Front Distribution and its supported actions
"""
def __init__(self, distribution_id):
if (cf_2_gcs.conf.AWS_ACCESS_KEY and cf_2_gcs.conf.AWS_SECRET_KEY):
self.cf_conn = CloudFrontConnection(cf_2_gcs.conf.AWS_ACCESS_KEY, cf_2_gcs.conf.AWS_SECRET_KEY)
try:
self.distribution = Distribution(connection=self.cf_conn, config=None, id=distribution_id)
except Exception:
log.error("Unable to associate distribution %s. Is the ID correct?" % distribution_id)
self.distribution = None
self.distribution_id = distribution_id
def get_root_url(self):
"""
Returns the root URL domain for the instance distribution id
"""
info = self.cf_conn.get_distribution_info(self.distribution_id)
protocol = str(info.config.Protocol)
distribution = str(info.domain_name)
return protocol + "://" + distribution
def get_public_url(self, path):
"""
Returns the public URL for a path
Args:
path (str): The pathname for the file relative to the CloudFront distribution
method and domain. Example: /test/video.mp4.
"""
return self.get_root_url() + path
def get_signed_url(self, path, expire_time=3600):
"""
Signs an URL with a CloudFront private key (for private content)
Args:
path (str): The pathname for the file relative to the CloudFront distribution
method and domain. Example: /test/video.mp4.
expire_time (Optional|int): How many seconds the signed URL will
be valid. Defaults to 3600 (1 hour).
"""
# setup cloudfront trusted keypair
keypair_id = cf_2_gcs.conf.CLOUDFRONT_KEYPAIR_ID
private_key_file = cf_2_gcs.conf.CLOUDFRONT_PRIVATE_KEY_FILE
# setup expire time from now
expire_time = int(time.time()+expire_time)
# append root domain to the url
url = self.get_root_url() + path
return self.distribution.create_signed_url(url=url, keypair_id=keypair_id, private_key_file=private_key_file, expire_time=expire_time)
示例3: get_distribution
# 需要导入模块: from boto.cloudfront import CloudFrontConnection [as 别名]
# 或者: from boto.cloudfront.CloudFrontConnection import get_distribution_info [as 别名]
def get_distribution(is_music=True):
"""
Get CloudFront distribution
"""
try:
cnn = CloudFrontConnection(aws_access_key_id=settings.PINNA_AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.PINNA_AWS_SECRET_KEY_ID)
if is_music:
dis = cnn.get_distribution_info(settings.PINNA_AWS_MUSIC_DATA_ID)
else:
dis = cnn.get_distribution_info(settings.PINNA_AWS_USER_PROFILE_ID)
return dis
except:
msg = traceback.format_exc()
LOG.error(msg)
return None