#!/usr/bin/env python3 from datetime import tzinfo, timedelta, datetime, date, timezone import boto3 cf = boto3.client('cloudfront') timestamp=str(datetime.timestamp(datetime.today())) distributions=cf.list_distributions() if distributions['DistributionList']['Quantity'] > 0: for distribution in distributions['DistributionList']['Items']: print("Distribution Id: " + distribution['Id']) print("Time: " + timestamp) cf.create_invalidation( DistributionId=distribution['Id'], InvalidationBatch={ 'Paths': { 'Quantity': 1, 'Items': [ '/*', ] }, 'CallerReference': timestamp } ) else: print("Error - No CloudFront Distributions Detected.")