Skip to content

Instantly share code, notes, and snippets.

@copernicus
Forked from nikgraf/cloud_front_root.py
Created October 21, 2010 13:18
Show Gist options
  • Save copernicus/638463 to your computer and use it in GitHub Desktop.
Save copernicus/638463 to your computer and use it in GitHub Desktop.
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