Skip to content

Commit a6f6189

Browse files
emmaling27Convex, Inc.
authored andcommitted
Open source aws_s3 crate (#34631)
GitOrigin-RevId: 8e147733cc785904fbf7a7689fd8d7329131d0dc
1 parent 158c0d0 commit a6f6189

File tree

7 files changed

+1094
-0
lines changed

7 files changed

+1094
-0
lines changed

Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ csv-async = "1.2"
1818
atomic_refcell = "0.1.13"
1919
aws-config = "1.1"
2020
aws-sdk-s3 = "1.14.0"
21+
aws-smithy-http = "0.60.8"
2122
aws-types = "1.1"
2223
axum = { version = "0.7", features = [ "ws", "original-uri", "macros", "multipart" ] }
2324
axum-extra = { version = "0.9.3", features = [ "typed-header", "cookie" ] }

crates/aws_s3/Cargo.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "aws_s3"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "LicenseRef-FSL-1.1-Apache-2.0"
6+
7+
[lib]
8+
doctest = false
9+
10+
[dependencies]
11+
anyhow = { workspace = true }
12+
async-trait = { workspace = true }
13+
aws-config = { workspace = true }
14+
aws-sdk-s3 = { workspace = true }
15+
aws-smithy-http = { workspace = true }
16+
aws_utils = { path = "../../crates/aws_utils" }
17+
bytes = { workspace = true }
18+
common = { path = "../../crates/common" }
19+
fastrace = { workspace = true }
20+
futures = { workspace = true }
21+
http = { workspace = true }
22+
metrics = { path = "../../crates/metrics" }
23+
pb = { path = "../../crates/pb" }
24+
serde_json = { workspace = true }
25+
storage = { path = "../../crates/storage" }
26+
tokio = { workspace = true }
27+
28+
[dev-dependencies]
29+
common = { path = "../../crates/common", features = ["testing"] }
30+
convex_macro = { path = "../../crates/convex_macro" }
31+
metrics = { path = "../../crates/metrics", features = ["testing"] }
32+
runtime = { path = "../../crates/runtime" }
33+
storage = { path = "../../crates/storage", features = ["testing"] }
34+
tokio-stream = { workspace = true }
35+
36+
[lints]
37+
workspace = true

crates/aws_s3/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(future_join)]
2+
#![feature(let_chains)]
3+
#![feature(coroutines)]
4+
#![feature(iter_from_coroutine)]
5+
#![feature(iterator_try_collect)]
6+
7+
use aws_sdk_s3::primitives::ByteStream;
8+
use bytes::Bytes;
9+
use futures::{
10+
Stream,
11+
TryStreamExt,
12+
};
13+
14+
mod metrics;
15+
pub mod storage;
16+
mod types;
17+
18+
/// For reasons unknown, the AWS SDK folks have decided that the public APIs
19+
/// can't contain any third-party types, so the `ByteStream` no longer
20+
/// implements `Stream`.
21+
/// We have to yoink this adapter trait from one of their internal crates to
22+
/// re-add the implementation.
23+
pub trait ByteStreamCompat {
24+
fn into_stream(self) -> impl Stream<Item = Result<Bytes, std::io::Error>>;
25+
}
26+
27+
impl ByteStreamCompat for ByteStream {
28+
fn into_stream(self) -> impl Stream<Item = Result<Bytes, std::io::Error>> {
29+
aws_smithy_http::futures_stream_adapter::FuturesStreamCompatByteStream::new(self)
30+
.map_err(Into::into)
31+
}
32+
}

crates/aws_s3/src/metrics.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use metrics::{
2+
log_distribution,
3+
register_convex_histogram,
4+
StatusTimer,
5+
STATUS_LABEL,
6+
};
7+
8+
register_convex_histogram!(
9+
SIGN_URL_SECONDS,
10+
"Time to fetch a presigned S3 link",
11+
&STATUS_LABEL
12+
);
13+
pub fn sign_url_timer() -> StatusTimer {
14+
StatusTimer::new(&SIGN_URL_SECONDS)
15+
}
16+
17+
register_convex_histogram!(
18+
AWS_S3_PART_UPLOAD_SIZE_BYTES,
19+
"The size in bytes of each part of an s3 multi part upload.",
20+
);
21+
pub fn log_aws_s3_part_upload_size_bytes(size: usize) {
22+
log_distribution(&AWS_S3_PART_UPLOAD_SIZE_BYTES, size as f64)
23+
}

0 commit comments

Comments
 (0)