commonware_deployer/ec2/
clean.rs1use crate::ec2::{
4 s3::{create_s3_client, delete_bucket_and_contents, is_no_such_bucket_error, S3_BUCKET_NAME},
5 Error, MONITORING_REGION,
6};
7use aws_config::Region;
8use tracing::info;
9
10pub async fn clean() -> Result<(), Error> {
12 info!(bucket = S3_BUCKET_NAME, "cleaning S3 bucket");
13
14 let s3_client = create_s3_client(Region::new(MONITORING_REGION)).await;
16
17 match delete_bucket_and_contents(&s3_client, S3_BUCKET_NAME).await {
19 Ok(()) => {
20 info!(bucket = S3_BUCKET_NAME, "cleaned S3 bucket");
21 }
22 Err(e) => {
23 if is_no_such_bucket_error(&e) {
24 info!(
25 bucket = S3_BUCKET_NAME,
26 "bucket does not exist, nothing to clean"
27 );
28 return Ok(());
29 }
30 return Err(e);
31 }
32 }
33
34 Ok(())
35}