Skip to content

Instantly share code, notes, and snippets.

@rfk
Created March 10, 2023 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfk/85d594339f249b513c619db38e2aaa8a to your computer and use it in GitHub Desktop.
Save rfk/85d594339f249b513c619db38e2aaa8a to your computer and use it in GitHub Desktop.
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