-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add S3 Example, rename s3preview => s3 (#413)
* Add S3 Example * Rename s3preview back to s3
- Loading branch information
Showing
4 changed files
with
131 additions
and
75 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "s3-helloworld" | ||
version = "0.1.0" | ||
authors = ["Russell Cohen <rcoh@amazon.com>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
s3 = { package = "aws-sdk-s3", path = "../../build/aws-sdk/s3" } | ||
smithy-http = { path = "../../build/aws-sdk/smithy-http" } | ||
tokio = { version = "1", features = ["full"] } | ||
tracing-subscriber = "0.2.18" | ||
|
||
[profile.dev] | ||
split-debuginfo = "unpacked" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use s3::Region; | ||
use smithy_http::byte_stream::ByteStream; | ||
use std::error::Error; | ||
use std::path::Path; | ||
use tracing_subscriber::fmt::format::FmtSpan; | ||
use tracing_subscriber::fmt::SubscriberBuilder; | ||
|
||
// Change these to your bucket & key | ||
const BUCKET: &str = "demo-bucket"; | ||
const KEY: &str = "demo-object"; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
SubscriberBuilder::default() | ||
.with_env_filter("info") | ||
.with_span_events(FmtSpan::CLOSE) | ||
.init(); | ||
let conf = s3::Config::builder() | ||
.region(Region::new("us-east-2")) | ||
.build(); | ||
let client = s3::Client::from_conf(conf); | ||
let resp = client.list_buckets().send().await?; | ||
for bucket in resp.buckets.unwrap_or_default() { | ||
println!("bucket: {:?}", bucket.name.expect("buckets have names")) | ||
} | ||
let body = ByteStream::from_path(Path::new("Cargo.toml")).await?; | ||
let resp = client | ||
.put_object() | ||
.bucket(BUCKET) | ||
.key(KEY) | ||
.body(body) | ||
.send(); | ||
let resp = resp.await?; | ||
println!("Upload success. Version: {:?}", resp.version_id); | ||
|
||
let resp = client.get_object().bucket(BUCKET).key(KEY).send().await?; | ||
let data = resp.body.collect().await?; | ||
println!("data: {:?}", data.into_bytes()); | ||
Ok(()) | ||
} |
Oops, something went wrong.