@@ -20,15 +20,25 @@ pub(crate) enum CdnKind {
2020
2121pub enum CdnBackend {
2222 Dummy ( Arc < Mutex < Vec < ( String , String ) > > > ) ,
23- CloudFront { runtime : Arc < Runtime > } ,
23+ CloudFront {
24+ runtime : Arc < Runtime > ,
25+ client : Client ,
26+ } ,
2427}
2528
2629impl CdnBackend {
2730 pub fn new ( config : & Arc < Config > , runtime : & Arc < Runtime > ) -> CdnBackend {
2831 match config. cdn_backend {
29- CdnKind :: CloudFront => Self :: CloudFront {
30- runtime : runtime. clone ( ) ,
31- } ,
32+ CdnKind :: CloudFront => {
33+ let shared_config = runtime. block_on ( aws_config:: load_from_env ( ) ) ;
34+ let config_builder = aws_sdk_cloudfront:: config:: Builder :: from ( & shared_config)
35+ . retry_config ( RetryConfig :: new ( ) . with_max_attempts ( 3 ) ) ;
36+
37+ Self :: CloudFront {
38+ runtime : runtime. clone ( ) ,
39+ client : Client :: from_conf ( config_builder. build ( ) ) ,
40+ }
41+ }
3242 CdnKind :: Dummy => Self :: Dummy ( Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ) ,
3343 }
3444 }
@@ -50,15 +60,14 @@ impl CdnBackend {
5060 let caller_reference = Uuid :: new_v4 ( ) ;
5161
5262 match * self {
53- CdnBackend :: CloudFront { ref runtime } => {
54- let shared_config = runtime. block_on ( aws_config:: load_from_env ( ) ) ;
55- let config_builder = aws_sdk_cloudfront:: config:: Builder :: from ( & shared_config)
56- . retry_config ( RetryConfig :: new ( ) . with_max_attempts ( 3 ) ) ;
57-
63+ CdnBackend :: CloudFront {
64+ ref runtime,
65+ ref client,
66+ } => {
5867 runtime. block_on ( CdnBackend :: cloudfront_invalidation (
59- & Client :: from_conf ( config_builder . build ( ) ) ,
68+ client ,
6069 distribution_id,
61- & format ! ( "{}" , caller_reference) ,
70+ & caller_reference. to_string ( ) ,
6271 path_patterns,
6372 ) ) ?;
6473 }
0 commit comments