Created
March 14, 2020 12:31
-
-
Save quiver/21ad5b2f6f4e934a5e3687317fe09c3e to your computer and use it in GitHub Desktop.
Sample script to create CloudFront invalidation
This file contains hidden or 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
''' | |
Invalidate Amazon CloudFront paths | |
API | |
- https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateInvalidation.html | |
- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudfront.html#CloudFront.Client.create_invalidation | |
''' | |
import random | |
import time | |
import boto3 | |
client = boto3.client('cloudfront') | |
DistributionId = 'EXAMPLE' | |
Items = ['/hello.jpg'] | |
def unique_string(prefix='cli'): | |
''' borrowed from aws-cli/awscli/customizations/cloudfront.py | |
''' | |
return '%s-%s-%s' % (prefix, int(time.time()), random.randint(1, 1000000)) | |
res = client.create_invalidation( | |
DistributionId=DistributionId, | |
InvalidationBatch = { | |
'Paths' : { | |
'Quantity': len(Items), | |
'Items': Items, | |
}, | |
'CallerReference' : unique_string() | |
} | |
) | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment