Skip to content

Commit

Permalink
Make Cloudfront caller references unique
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Aug 7, 2024
1 parent 548f0ec commit 1704eff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions art/cloudfront.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import time
from typing import Any

log = logging.getLogger(__name__)
Expand All @@ -15,16 +16,22 @@ def get_cloudfront_client() -> Any:

def execute_cloudfront_invalidations(invalidations: dict[str, set[str]]) -> None:
cf_client = get_cloudfront_client()
ts = int(time.time())
for dist_id, paths in invalidations.items():
log.info("Creating CloudFront invalidation for %s: %d paths", dist_id, len(paths))
caller_reference = f"art-{dist_id}-{ts}"
inv = cf_client.create_invalidation(
DistributionId=dist_id,
InvalidationBatch={
"Paths": {
"Quantity": len(paths),
"Items": sorted(paths),
},
"CallerReference": "art",
"CallerReference": caller_reference,
},
)
log.info("Created CloudFront invalidation: %s", inv["Invalidation"]["Id"])
log.info(
"Created CloudFront invalidation with caller reference %s: %s",
caller_reference,
inv["Invalidation"]["Id"],
)

0 comments on commit 1704eff

Please sign in to comment.