Skip to content

Commit e827693

Browse files
committed
added CloudFront invalidate_paths method
1 parent 55c3b1b commit e827693

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

osbot_aws/aws/cloud_front/Cloud_Front.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from osbot_aws.apis.Session import Session
2-
3-
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
4-
1+
import time
2+
from typing import List
3+
from osbot_utils.decorators.methods.type_safe import type_safe
4+
from osbot_aws.apis.Session import Session
5+
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
56

67
class Cloud_Front(Kwargs_To_Self):
78

@@ -14,3 +15,14 @@ def distributions(self):
1415
items = response.get('DistributionList', {}).get('Items', [])
1516
return items
1617

18+
def invalidate_path(self, distribution_id: str, paths: str):
19+
return self.invalidate_paths(distribution_id, [paths])
20+
21+
@type_safe
22+
def invalidate_paths(self, distribution_id:str, paths: List[str]):
23+
kwargs = dict(DistributionId = distribution_id,
24+
InvalidationBatch = { 'Paths' : { 'Quantity': len(paths) ,
25+
'Items' : paths },
26+
'CallerReference': f'invalidation-{int(time.time()) }' }) # Unique reference
27+
response = self.client().create_invalidation(**kwargs)
28+
return response

0 commit comments

Comments
 (0)