Skip to content

Instantly share code, notes, and snippets.

@nikgraf
Created October 21, 2010 01:16
Show Gist options
  • Save nikgraf/637725 to your computer and use it in GitHub Desktop.
Save nikgraf/637725 to your computer and use it in GitHub Desktop.
sets default_root_object of an aws cloud front distribution
from boto.cloudfront import CloudFrontConnection
def update_default_root_object(searched_origin, aws_access_key_id, aws_secret_access_key, default_root_object='index.html'):
""" sets default_root_object of an aws cloud front distribution
for futher information checkout http://boto.s3.amazonaws.com/ref/cloudfront.html
or http://github.com/boto/boto/tree/master/boto/cloudfront
"""
connection = CloudFrontConnection(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
distro_summary = [distro_summary for distro_summary in connection.get_all_distributions() if distro_summary.origin == searched_origin][0]
distro = distro_summary.get_distribution()
distro.update(default_root_object=default_root_object)
print(connection.get_distribution_config(distro.id).to_xml())
if __name__ == '__main__':
searched_origin = '<bucket_name>.s3.amazonaws.com'
aws_access_key_id = '<aws_access_key_id>'
aws_secret_access_key = '<aws_secret_access_key>'
update_default_root_object(searched_origin=searched_origin,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment