Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5ee9aa5

Browse files
committedSep 25, 2022
move cloudfront client initialization into startup
1 parent b17ead3 commit 5ee9aa5

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed
 

‎src/cdn.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ pub(crate) enum CdnKind {
2020

2121
pub 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

2629
impl 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

Comments
 (0)
Please sign in to comment.