Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: cargo check --workspace --all --bins --examples

- name: wstd tests
run: cargo test -p wstd -p wstd-axum -p wstd-aws --target wasm32-wasip2 -- --nocapture
run: cargo test -p wstd -p wstd-axum --target wasm32-wasip2 -- --nocapture

- name: test-programs tests
run: cargo test -p test-programs -- --nocapture
Expand Down
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true

[workspace]
members = ["aws",
members = [
"axum",
"axum/macro",
"macro",
Expand All @@ -59,7 +59,7 @@ license = "Apache-2.0 WITH LLVM-exception"
repository = "https://github.com/bytecodealliance/wstd"
keywords = ["WebAssembly", "async", "stdlib", "Components"]
categories = ["wasm", "asynchronous"]
rust-version = "1.88"
rust-version = "1.91.1"
authors = [
"Yoshua Wuyts <rust@yosh.is>",
"Pat Hickey <pat@moreproductive.org>",
Expand All @@ -69,11 +69,6 @@ authors = [
[workspace.dependencies]
anyhow = "1"
async-task = "4.7"
aws-config = { version = "1.8.8", default-features = false }
aws-sdk-s3 = { version = "1.108.0", default-features = false }
aws-smithy-async = { version = "1.2.6", default-features = false }
aws-smithy-types = { version = "1.3.3", default-features = false }
aws-smithy-runtime-api = { version = "1.9.1", default-features = false }
axum = { version = "0.8.6", default-features = false }
bytes = "1.10.1"
cargo_metadata = "0.22"
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions aws-example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "wstd-aws-example"
description = "demonstrate use of aws-smithy-wasm wstd support"
publish = false
version = "0.6.5"
edition = "2024"
license = "Apache-2.0 WITH LLVM-exception"
repository = "https://github.com/bytecodealliance/wstd"
keywords = ["WebAssembly", "async", "stdlib", "Components"]
categories = ["wasm", "asynchronous"]
rust-version = "1.91.1"
authors = [
"Pat Hickey <pat@moreproductive.org>",
]
[[bin]]
name = "s3"

[dependencies]
anyhow = "1"
clap = { version = "4.5", features = ["derive"] }
aws-config = { version = "1.8.15", default-features = false }
aws-sdk-s3 = { version = "1.125.0", default-features = false }
aws-smithy-wasm = "0.1.10"
wstd = "0.6.5"

[workspace]
53 changes: 36 additions & 17 deletions aws/README.md → aws-example/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@

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

This crate provides support for using the AWS Rust SDK for the `wasm32-wasip2`
target using the [`wstd`] crate.
The AWS Rust SDK has support for using the [`wstd`] crate on the
`wasm32-wasip2` target to use the wasi-http interface. This example shows how
to use it.

## TL;DR

* depend on `aws-*` crates released recently enough to have MSRV of 1.91.1 (on
or after March 4, 2026). Use `default-features = false` so tokio doesn't get
sucked in.
* depend on `aws-smithy-wasm` and setup your `Config` with:
```
config
.sleep_impl(aws_smithy_wasm::wasi::WasiSleep)
.http_client(aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build())
```

## Explanation

In many wasi settings, its necessary or desirable to use the wasi-http
interface to make http requests. Wasi-http interfaces provide an http
Expand All @@ -17,14 +32,16 @@ and if they do, they will not use the wasi-http interfaces. To avoid using
http over sockets, make sure to set the `default-features = false` setting
when depending on any `aws-*` crates in your project.

To configure `wstd`'s wasi-http client for the AWS Rust SDK, provide
`wstd_aws::sleep_impl()` and `wstd_aws::http_client()` to your
To configure the AWS Rust SDK to use `wstd`'s wasi-http client, use the
[`aws_smithy_crate`](https://docs.rs/aws-smithy-wasm/latest/aws_smithy_wasm/)
at version 0.10.0 or later. Provide `aws_smithy_wasm::wasi::WasiSleep` and
`aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build()` to your
[`aws_config::ConfigLoader`]:

```
let config = aws_config::defaults(BehaviorVersion::latest())
.sleep_impl(wstd_aws::sleep_impl())
.http_client(wstd_aws::http_client())
.sleep_impl(aws_smithy_wasm::wasi::WasiSleep)
.http_client(aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build())
...;
```

Expand All @@ -44,11 +61,12 @@ a single function.
Compile it with:

```sh
cargo build -p wstd-aws --target wasm32-wasip2 --release --examples
cargo build -p wstd-aws-example --target wasm32-wasip2 --release
```

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

Run it with:
```sh
Expand All @@ -57,19 +75,20 @@ wasmtime run -Shttp \
--env AWS_SECRET_ACCESS_KEY \
--env AWS_SESSION_TOKEN \
--dir .::. \
target/wasm32-wasip2/release/examples/s3.wasm
target/wasm32-wasip2/release/s3.wasm \
--region us-west-2 \
--bucket wstd-example-bucket
```

or alternatively run it with:
```sh
cargo run --target wasm32-wasip2 -p wstd-aws --example s3
cargo run --target wasm32-wasip2 -p wstd-aws-example --example s3 -- \
--region us-west-2 --bucket wstd-example-bucket
```

which uses the wasmtime cli, as above, via configiration found in this
workspace's `.cargo/config`.

By default, this script accesses the `wstd-example-bucket` in `us-west-2`.
To change the bucket or region, use the `--bucket` and `--region` cli
flags before the subcommand.
workspace's `.cargo/config.toml`.

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

23 changes: 8 additions & 15 deletions aws/examples/s3.rs → aws-example/src/bin/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ use aws_sdk_s3::Client;
#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
struct Opts {
/// The AWS Region. Defaults to us-west-2 if not provided.
/// The AWS Region for the s3 bucket.
#[arg(short, long)]
region: Option<String>,
/// The name of the bucket. Defaults to wstd-example-bucket if not
/// provided.
region: String,
/// The name of the s3 bucket.
#[arg(short, long)]
bucket: Option<String>,
bucket: String,

#[command(subcommand)]
command: Option<Command>,
Expand All @@ -73,19 +72,13 @@ enum Command {
#[wstd::main]
async fn main() -> Result<()> {
let opts = Opts::parse();
let region = opts
.region
.clone()
.unwrap_or_else(|| "us-west-2".to_owned());
let bucket = opts
.bucket
.clone()
.unwrap_or_else(|| "wstd-example-bucket".to_owned());
let region = opts.region;
let bucket = opts.bucket;

let config = aws_config::defaults(BehaviorVersion::latest())
.region(Region::new(region))
.sleep_impl(wstd_aws::sleep_impl())
.http_client(wstd_aws::http_client())
.sleep_impl(aws_smithy_wasm::wasi::WasiSleep)
.http_client(aws_smithy_wasm::wasi::WasiHttpClientBuilder::new().build())
.load()
.await;

Expand Down
31 changes: 0 additions & 31 deletions aws/Cargo.toml

This file was deleted.

101 changes: 0 additions & 101 deletions aws/src/lib.rs

This file was deleted.

Loading