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
722In many wasi settings, its necessary or desirable to use the wasi-http
823interface 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
1732http over sockets, make sure to set the `default-features = false` setting
1833when 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.
4461Compile 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
5067When 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
5371Run 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
6383or 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-
6888which 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
0 commit comments