Created
October 4, 2017 21:54
-
-
Save TheMattSchiller/2c364319dd5a9b7da43747a1e52f1a7f to your computer and use it in GitHub Desktop.
CloudFront Invalidator
This file contains 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
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