Created
February 8, 2022 09:45
-
-
Save joshuarobinson/f9c806dc6e8128c073a7460e1ca9f52b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use aws_sdk_s3::{Client, Endpoint, Error, Region}; | |
use http::Uri; | |
use awaitgroup::WaitGroup; | |
#[tokio::main] | |
async fn main() -> Result<(), Error> { | |
let bucket = "joshuarobinson"; | |
let endpoint = "http://10.62.64.200"; | |
let prefix = ""; | |
let region = Region::new("us-west-2"); | |
let conf = aws_config::load_from_env().await; | |
let ep = Endpoint::immutable(Uri::from_static(endpoint)); | |
let s3_conf = aws_sdk_s3::config::Builder::from(&conf) | |
.endpoint_resolver(ep) | |
.region(region) | |
.build(); | |
let client = Client::from_conf(s3_conf); | |
println!(); | |
let mut wg = WaitGroup::new(); | |
let mut continuation_token = String::from(""); | |
loop { | |
let resp = client.list_objects_v2().bucket(bucket).prefix(prefix).continuation_token(continuation_token).send().await?; | |
for object in resp.contents().unwrap_or_default() { | |
let key = object.key().unwrap_or_default(); | |
let req = client.head_object().bucket(bucket).key(key).send(); | |
let worker = wg.worker(); | |
tokio::spawn(async move { | |
let resp = match req.await { | |
Ok(r) => r, | |
Err(e) => panic!("HeadObject Error: {:?}", e), | |
}; | |
let info = resp.metadata().unwrap(); | |
for (key, value) in info.iter() { | |
println!("{}: {}", key, value); | |
} | |
worker.done(); | |
}); | |
} | |
if resp.is_truncated() { | |
continuation_token = resp.next_continuation_token().unwrap().to_string(); | |
} else { | |
break; | |
} | |
} | |
wg.wait().await; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment