From 0c699d40b8a7492bc468dcca75ea1d0615c706f1 Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Sun, 12 Oct 2014 18:22:07 -0700 Subject: [PATCH] reset cache cf --- reset-cf-cache/Dockerfile | 9 +++++++++ reset-cf-cache/reset-cache.py | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 reset-cf-cache/Dockerfile create mode 100644 reset-cf-cache/reset-cache.py diff --git a/reset-cf-cache/Dockerfile b/reset-cf-cache/Dockerfile new file mode 100644 index 0000000..82211bc --- /dev/null +++ b/reset-cf-cache/Dockerfile @@ -0,0 +1,9 @@ +FROM python:2.7.8 +MAINTAINER Jessica Frazelle + +RUN pip install boto + +ADD reset-cache.py /bin/reset-cache +RUN chmod +x /bin/reset-cache + +CMD [ "reset-cache" ] \ No newline at end of file diff --git a/reset-cf-cache/reset-cache.py b/reset-cf-cache/reset-cache.py new file mode 100644 index 0000000..4a50f88 --- /dev/null +++ b/reset-cf-cache/reset-cache.py @@ -0,0 +1,38 @@ +#!/usr/local/bin/python + +import boto +import os +import sys + + +access_key = os.getenv("AWS_ACCESS_KEY") +access_secret = os.getenv("AWS_SECRET_KEY") +cloudfront_dist = os.getenv("AWS_CF_DISTRIBUTION_ID") +bucket = os.getenv("AWS_S3_BUCKET") + +if access_key == "" or access_key is None: + print "Please set AWS_ACCESS_KEY env variable." + sys.exit(1) +elif access_secret == "" or access_secret is None: + print "Please set AWS_SECRET_KEY env variable." + sys.exit(1) +elif cloudfront_dist == "" or cloudfront_dist is None: + print "Please set AWS_CF_DISTRIBUTION_ID env variable." + sys.exit(1) +elif bucket == "" or bucket is None: + print "Please set AWS_S3_BUCKET env variable." + sys.exit(1) + +# get the paths from s3 +s3_conn = boto.connect_s3(access_key, access_secret) +docs = s3_conn.get_bucket(bucket) +items = [] + +for key in docs.list(): + items.append(key.name) + +cf_conn = boto.connect_cloudfront(access_key, access_secret) +inval_req = cf_conn.create_invalidation_request(cloudfront_dist, items) + +print inval_req +sys.exit(0) \ No newline at end of file