Skip to content

Commit 7517dcc

Browse files
authored
no more wstd-aws crate: instead example shows upstreamed functionality (#122)
1 parent dea316a commit 7517dcc

File tree

10 files changed

+122
-217
lines changed

10 files changed

+122
-217
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run: cargo check --workspace --all --bins --examples
5353

5454
- name: wstd tests
55-
run: cargo test -p wstd -p wstd-axum -p wstd-aws --target wasm32-wasip2 -- --nocapture
55+
run: cargo test -p wstd -p wstd-axum --target wasm32-wasip2 -- --nocapture
5656

5757
- name: test-programs tests
5858
run: cargo test -p test-programs -- --nocapture

Cargo.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ serde = { workspace = true, features = ["derive"] }
4444
serde_json.workspace = true
4545

4646
[workspace]
47-
members = ["aws",
47+
members = [
4848
"axum",
4949
"axum/macro",
5050
"macro",
@@ -59,7 +59,7 @@ license = "Apache-2.0 WITH LLVM-exception"
5959
repository = "https://github.com/bytecodealliance/wstd"
6060
keywords = ["WebAssembly", "async", "stdlib", "Components"]
6161
categories = ["wasm", "asynchronous"]
62-
rust-version = "1.88"
62+
rust-version = "1.91.1"
6363
authors = [
6464
"Yoshua Wuyts <rust@yosh.is>",
6565
"Pat Hickey <pat@moreproductive.org>",
@@ -69,11 +69,6 @@ authors = [
6969
[workspace.dependencies]
7070
anyhow = "1"
7171
async-task = "4.7"
72-
aws-config = { version = "1.8.8", default-features = false }
73-
aws-sdk-s3 = { version = "1.108.0", default-features = false }
74-
aws-smithy-async = { version = "1.2.6", default-features = false }
75-
aws-smithy-types = { version = "1.3.3", default-features = false }
76-
aws-smithy-runtime-api = { version = "1.9.1", default-features = false }
7772
axum = { version = "0.8.6", default-features = false }
7873
bytes = "1.10.1"
7974
cargo_metadata = "0.22"
File renamed without changes.

aws-example/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "wstd-aws-example"
3+
description = "demonstrate use of aws-smithy-wasm wstd support"
4+
publish = false
5+
version = "0.6.5"
6+
edition = "2024"
7+
license = "Apache-2.0 WITH LLVM-exception"
8+
repository = "https://github.com/bytecodealliance/wstd"
9+
keywords = ["WebAssembly", "async", "stdlib", "Components"]
10+
categories = ["wasm", "asynchronous"]
11+
rust-version = "1.91.1"
12+
authors = [
13+
"Pat Hickey <pat@moreproductive.org>",
14+
]
15+
[[bin]]
16+
name = "s3"
17+
18+
[dependencies]
19+
anyhow = "1"
20+
clap = { version = "4.5", features = ["derive"] }
21+
aws-config = { version = "1.8.15", default-features = false }
22+
aws-sdk-s3 = { version = "1.125.0", default-features = false }
23+
aws-smithy-wasm = "0.1.10"
24+
wstd = "0.6.5"
25+
26+
[workspace]

aws/README.md renamed to aws-example/README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11

2-
# wstd-aws: wstd support for the AWS Rust SDK
2+
# wstd-aws-example: using wstd support in the AWS Rust SDK
33

4-
This crate provides support for using the AWS Rust SDK for the `wasm32-wasip2`
5-
target using the [`wstd`] crate.
4+
The AWS Rust SDK has support for using the [`wstd`] crate on the
5+
`wasm32-wasip2` target to use the wasi-http interface. This example shows how
6+
to use it.
7+
8+
## TL;DR
9+
10+
* depend on `aws-*` crates released recently enough to have MSRV of 1.91.1 (on
11+
or after March 4, 2026). Use `default-features = false` so tokio doesn't get
12+
sucked in.
13+
* depend on `aws-smithy-wasm` and setup your `Config` with:
14+
```
15+
config
16+
.sleep_impl(aws_smithy_wasm::wasi::WasiSleep)
17+
.http_client(aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build())
18+
```
19+
20+
## Explanation
621
722
In many wasi settings, its necessary or desirable to use the wasi-http
823
interface to make http requests. Wasi-http interfaces provide an http
@@ -17,14 +32,16 @@ and if they do, they will not use the wasi-http interfaces. To avoid using
1732
http over sockets, make sure to set the `default-features = false` setting
1833
when depending on any `aws-*` crates in your project.
1934
20-
To configure `wstd`'s wasi-http client for the AWS Rust SDK, provide
21-
`wstd_aws::sleep_impl()` and `wstd_aws::http_client()` to your
35+
To configure the AWS Rust SDK to use `wstd`'s wasi-http client, use the
36+
[`aws_smithy_crate`](https://docs.rs/aws-smithy-wasm/latest/aws_smithy_wasm/)
37+
at version 0.10.0 or later. Provide `aws_smithy_wasm::wasi::WasiSleep` and
38+
`aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build()` to your
2239
[`aws_config::ConfigLoader`]:
2340
2441
```
2542
let config = aws_config::defaults(BehaviorVersion::latest())
26-
.sleep_impl(wstd_aws::sleep_impl())
27-
.http_client(wstd_aws::http_client())
43+
.sleep_impl(aws_smithy_wasm::wasi::WasiSleep)
44+
.http_client(aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build())
2845
...;
2946
```
3047
@@ -44,11 +61,12 @@ a single function.
4461
Compile it with:
4562
4663
```sh
47-
cargo build -p wstd-aws --target wasm32-wasip2 --release --examples
64+
cargo build -p wstd-aws-example --target wasm32-wasip2 --release
4865
```
4966

5067
When running this example, you will need AWS credentials provided in environment
51-
variables.
68+
variables, and you should substitute in a region and bucket where your
69+
credentials have permissions to list the bucket and read items.
5270

5371
Run it with:
5472
```sh
@@ -57,19 +75,20 @@ wasmtime run -Shttp \
5775
--env AWS_SECRET_ACCESS_KEY \
5876
--env AWS_SESSION_TOKEN \
5977
--dir .::. \
60-
target/wasm32-wasip2/release/examples/s3.wasm
78+
target/wasm32-wasip2/release/s3.wasm \
79+
--region us-west-2 \
80+
--bucket wstd-example-bucket
6181
```
6282

6383
or alternatively run it with:
6484
```sh
65-
cargo run --target wasm32-wasip2 -p wstd-aws --example s3
85+
cargo run --target wasm32-wasip2 -p wstd-aws-example --example s3 -- \
86+
--region us-west-2 --bucket wstd-example-bucket
6687
```
67-
6888
which uses the wasmtime cli, as above, via configiration found in this
69-
workspace's `.cargo/config`.
70-
71-
By default, this script accesses the `wstd-example-bucket` in `us-west-2`.
72-
To change the bucket or region, use the `--bucket` and `--region` cli
73-
flags before the subcommand.
89+
workspace's `.cargo/config.toml`.
7490

91+
By default, the subcommand `list` will be run, listing the contents of the
92+
bucket. To get an item from the bucket, use the subcommand `get <key> [-o
93+
<output>]`. Use `--help` when in doubt.
7594

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ use aws_sdk_s3::Client;
4848
#[derive(Debug, Parser)]
4949
#[command(version, about, long_about = None)]
5050
struct Opts {
51-
/// The AWS Region. Defaults to us-west-2 if not provided.
51+
/// The AWS Region for the s3 bucket.
5252
#[arg(short, long)]
53-
region: Option<String>,
54-
/// The name of the bucket. Defaults to wstd-example-bucket if not
55-
/// provided.
53+
region: String,
54+
/// The name of the s3 bucket.
5655
#[arg(short, long)]
57-
bucket: Option<String>,
56+
bucket: String,
5857

5958
#[command(subcommand)]
6059
command: Option<Command>,
@@ -73,19 +72,13 @@ enum Command {
7372
#[wstd::main]
7473
async fn main() -> Result<()> {
7574
let opts = Opts::parse();
76-
let region = opts
77-
.region
78-
.clone()
79-
.unwrap_or_else(|| "us-west-2".to_owned());
80-
let bucket = opts
81-
.bucket
82-
.clone()
83-
.unwrap_or_else(|| "wstd-example-bucket".to_owned());
75+
let region = opts.region;
76+
let bucket = opts.bucket;
8477

8578
let config = aws_config::defaults(BehaviorVersion::latest())
8679
.region(Region::new(region))
87-
.sleep_impl(wstd_aws::sleep_impl())
88-
.http_client(wstd_aws::http_client())
80+
.sleep_impl(aws_smithy_wasm::wasi::WasiSleep)
81+
.http_client(aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build())
8982
.load()
9083
.await;
9184

aws/Cargo.toml

Lines changed: 0 additions & 31 deletions
This file was deleted.

aws/src/lib.rs

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)