Created
March 10, 2023 01:12
-
-
Save rfk/85d594339f249b513c619db38e2aaa8a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 anyhow::{Context, Result}; | |
use cobalt_aws::s3; | |
use futures::io::AsyncReadExt; | |
use tokio::runtime::Runtime; | |
fn main() -> Result<()> { | |
// This "block_on" magic lets you execute an "async" function without having | |
// to worry about making all of the surrounding code also be an "async" function. | |
let config = Runtime::new()?.block_on( | |
cobalt_aws::config::load_from_env() | |
)?; | |
let client = s3::Client::new(&config); | |
// You can use this to read an S3 object into a string, for further processing. | |
let body = Runtime::new()?.block_on(async { | |
let mut body = String::new(); | |
s3::get_object( | |
&client, | |
"ctc-labelbox-targeted-annalise-ai-prod", | |
"jsons/imed-mdm/ctc_bulk/0000398456f23fb8146417637a5eadc9cea2c936ed3eefab08c07d029052d295/020c3623073ecee0f92b8fa06dc7e36225d6bd3e9a214b2e5b9d4494cb2841cd.json" | |
).await | |
.context("Failed to read from S3")? | |
.read_to_string(&mut body).await?; | |
anyhow::Ok(body) | |
})?; | |
println!("GOT: {}", body); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment