Created
October 24, 2018 14:07
-
-
Save jolexa/e58ea2ec19cf3067d0ddfbdc98bbaf6d to your computer and use it in GitHub Desktop.
Invalidate CloudFront Cache with boto3
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 time import time | |
import sys | |
import boto3 | |
client = boto3.client('cloudfront') | |
# Uncomment this to pass a URL to the script | |
#def get_id(url): | |
# print("get_id args: {0}".format(url)) | |
# # url: asdf.cloudfront.net | |
# # return: E2134123ASDF | |
# # where E2134123ASDF is the id of asdf.cloudfront.net | |
# paginator = client.get_paginator('list_distributions') | |
# response_iterator = paginator.paginate() | |
# for i in response_iterator: | |
# for j in i['DistributionList']['Items']: | |
# if j['Aliases']['Items'][0] == url: | |
# return j['Id'] | |
response = client.create_invalidation( | |
#DistributionId=get_id(sys.argv[1]), | |
DistributionId=sys.argv[1], | |
InvalidationBatch={ | |
'Paths': { | |
'Quantity': 1, | |
'Items': [ | |
'/*' | |
], | |
}, | |
'CallerReference': str(time()).replace(".", "") | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for that!