Skip to content

Instantly share code, notes, and snippets.

@TheMattSchiller
Created October 4, 2017 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheMattSchiller/2c364319dd5a9b7da43747a1e52f1a7f to your computer and use it in GitHub Desktop.
Save TheMattSchiller/2c364319dd5a9b7da43747a1e52f1a7f to your computer and use it in GitHub Desktop.
CloudFront Invalidator
from __future__ import print_function
import boto3
import time
def lambda_handler(event, context):
path = []
for items in event["Records"]:
if items["s3"]["object"]["key"] == "index.html":
path.append("/")
else:
path.append("/" + items["s3"]["object"]["key"])
print(path)
client = boto3.client('cloudfront')
invalidation = client.create_invalidation(DistributionId='E29ZTFX5Z7QMUB',
InvalidationBatch={
'Paths': {
'Quantity': 1,
'Items': path
},
'CallerReference': str(time.time())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment