{"id":69,"date":"2019-05-22T14:10:13","date_gmt":"2019-05-22T04:10:13","guid":{"rendered":"http:\/\/stuff.magicwilly.home\/?p=69"},"modified":"2019-05-22T14:10:13","modified_gmt":"2019-05-22T04:10:13","slug":"python-invalidation-script","status":"publish","type":"post","link":"http:\/\/stuff2.mygeekvps.net\/index.php\/2019\/05\/22\/python-invalidation-script\/","title":{"rendered":"Python Cloudfront Invalidation Script"},"content":{"rendered":"<pre lang=\"python\" cssfile=\"none\">\n#!\/usr\/bin\/env python3\nfrom datetime import tzinfo, timedelta, datetime, date, timezone\nimport boto3\ncf = boto3.client('cloudfront')\ntimestamp=str(datetime.timestamp(datetime.today()))\ndistributions=cf.list_distributions()\nif distributions['DistributionList']['Quantity'] > 0:\n  for distribution in distributions['DistributionList']['Items']:\n    print(\"Distribution Id: \" + distribution['Id'])\n    print(\"Time: \" + timestamp)\n    cf.create_invalidation(\n        DistributionId=distribution['Id'],\n        InvalidationBatch={\n            'Paths': {\n                'Quantity': 1,\n                'Items': [\n                    '\/*',\n                ]\n            },\n            'CallerReference': timestamp\n        }\n    )\nelse:\n   print(\"Error - No CloudFront Distributions Detected.\")\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/env python3 from datetime import tzinfo, timedelta, datetime, date, timezone import boto3 cf = boto3.client(&#8216;cloudfront&#8217;) timestamp=str(datetime.timestamp(datetime.today())) distributions=cf.list_distributions() if distributions[&#8216;DistributionList&#8217;][&#8216;Quantity&#8217;] > 0: for distribution in distributions[&#8216;DistributionList&#8217;][&#8216;Items&#8217;]: print(&#8220;Distribution Id: &#8221; + distribution[&#8216;Id&#8217;]) print(&#8220;Time: &#8221; + timestamp) cf.create_invalidation( DistributionId=distribution[&#8216;Id&#8217;], InvalidationBatch={ &#8216;Paths&#8217;: { &#8216;Quantity&#8217;:<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"http:\/\/stuff2.mygeekvps.net\/index.php\/2019\/05\/22\/python-invalidation-script\/\">Read more <span class=\"screen-reader-text\">Python Cloudfront Invalidation Script<\/span><span class=\"meta-nav\"> &#8250;<\/span><\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-python","category-web"],"_links":{"self":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":0,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"wp:attachment":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}