Last active
December 16, 2015 17:28
-
-
Save avargas/5470193 to your computer and use it in GitHub Desktop.
invalidates cloudfront files easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse, boto | |
AWS_ACCESS_KEY = '' | |
AWS_SECRET_KEY = '' | |
AWS_CLOUDFRONT_ID = "" | |
def invalidate (f, print_debug=False): | |
from boto.cloudfront import CloudFrontConnection | |
con = CloudFrontConnection(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
if print_debug: | |
requests = con.get_invalidation_requests(AWS_CLOUDFRONT_ID) | |
for req in requests: | |
print "invalidation " + req.id + " (" + req.status + ")" | |
print "paths: " | |
for path in req.get_invalidation_request().paths: | |
print " " + path | |
else: | |
if type(f) == str: | |
print "invalidating " + f | |
con.create_invalidation_request(AWS_CLOUDFRONT_ID, f) | |
else: | |
for e in f: | |
print "invalidating " + e | |
con.create_invalidation_request(AWS_CLOUDFRONT_ID, f) | |
parser = argparse.ArgumentParser(description='cloudfront') | |
parser.add_argument('--cfinvalidations', action='store_true', help='cf invalidations') | |
parser.add_argument('--cfinvalidate', type=str, help='invalidates cf file') | |
if args.cfinvalidations: | |
invalidate(None, print_debug=True) | |
exit() | |
if args.cfinvalidate: | |
invalidate(args.cfinvalidate) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment