Skip to content

@harperreed /create_custom_origin.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
creates a custom origin for cloudfront. EASY CDN!
import boto
# requires cf_customorigin branch
# https://github.com/boto/boto/tree/cf_customorigin
origin_domain = 'www.example.org'
cdn_cname = ['media.example.org']
caller_reference = 'exmaple Distribution'
c = boto.connect_cloudfront()
d = c.create_custom_distribution(
dns_name=origin_domain,
enabled=True,
caller_reference=caller_reference,
cnames=cdn_cname
)
print 'cname '+ cdn_cname + ' to ' d.domain_name
import datetime
from boto.cloudfront import CloudFrontConnection
import os
import sys
rootdir = '../app/static/'
media_list = []
for root, subFolders, files in os.walk(rootdir):
root = root.replace('../app','')
for f in files:
media_list.append(root + '/'+ f)
media_list.append(root.replace('static/','') + f)
#any media that didn't make it (look in app.yaml)
default_media_list = [
'/favicon.ico',
'/robots.txt',
'/',
]
clear_list = media_list + default_media_list
aws_cloudfront_distributions = ['EXXXXXXXXXXXXXXX1','EXXXXXXXXXXXXXXX2']
print "About to clear " + str(len(clear_list)) + " items from cloudfront"
conn = CloudFrontConnection()
for cf_distro in aws_cloudfront_distributions:
try:
result = conn.create_invalidation_request(cf_distro, clear_list)
print "Cleared " +str(len(result)) + " items successfully from " + cf_distro
except:
print "error occurred. please try again in 15 minutes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.