-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
aws-smithy-wasm
crate with WASI http client (#3409)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> This change adds a new crate, `aws-smithy-wasm`, that exports a SDK compatible WASI http client. This is a continuation of the work in #2520 using the now stabilized WASI 0.2.0 interfaces from the [wasi crate](https://crates.io/crates/wasi). This supports, but does not finalize the work for #2087 ## Description <!--- Describe your changes in detail --> Add a new crate, `aws-smithy-wasm` which exports a function `wasi_http_client` that will provide the user with a WASI compatible http client. This client is implemented by using the `wasi::http::outgoing_handler` [ref](https://docs.rs/wasi/0.12.0+wasi-0.2.0/wasi/http/outgoing_handler/index.html) along with some utility implementations of `TryFrom` to transform back and worth between the types from the `http` crate and the `wasi::http` types. It also exports a unit struct `WasmSleep` that impls the `AsyncSleep` trait needed by the SDK. ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> This is tested via an integration test in `aws/sdk/integration-tests/webassembly` that uses the wasi http-client to vuild a config and an operation (that is not sent). It is further tested in a new canary (`wasm_canary`) that calls the S3 `list_objects_v2` API. ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [X] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Eduardo Rodrigues <eduardomourar@users.noreply.github.com> Co-authored-by: Eduardo de Moura Rodrigues <16357187+eduardomourar@users.noreply.github.com> Co-authored-by: ysaito1001 <awsaito@amazon.com> Co-authored-by: John DiSanti <jdisanti@amazon.com> Co-authored-by: Russell Cohen <rcoh@amazon.com> Co-authored-by: John DiSanti <john@vinylsquid.com>
- Loading branch information
1 parent
5b9d0c0
commit d95cc86
Showing
35 changed files
with
2,371 additions
and
152 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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Cargo.lock | ||
target/ | ||
webassembly/src/bindings.rs |
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
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
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
32 changes: 0 additions & 32 deletions
32
aws/sdk/integration-tests/webassembly/src/default_config.rs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,54 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_config::retry::RetryConfig; | ||
use aws_sdk_s3::operation::list_objects_v2::builders::ListObjectsV2FluentBuilder; | ||
use aws_sdk_s3::Client; | ||
use aws_smithy_types::timeout::TimeoutConfig; | ||
use aws_smithy_wasm::wasi::WasiHttpClientBuilder; | ||
|
||
pub(crate) async fn get_default_wasi_config() -> aws_config::SdkConfig { | ||
let http_client = WasiHttpClientBuilder::new().build(); | ||
aws_config::from_env() | ||
.region("us-east-2") | ||
.timeout_config(TimeoutConfig::disabled()) | ||
.retry_config(RetryConfig::disabled()) | ||
.no_credentials() | ||
.http_client(http_client) | ||
.load() | ||
.await | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn test_default_config() { | ||
let shared_config = get_default_wasi_config().await; | ||
let client = aws_sdk_s3::Client::new(&shared_config); | ||
assert_eq!(client.config().region().unwrap().to_string(), "us-east-2") | ||
} | ||
|
||
async fn s3_list_objects_operation() -> ListObjectsV2FluentBuilder { | ||
let shared_config = get_default_wasi_config().await; | ||
let client = Client::new(&shared_config); | ||
let operation = client | ||
.list_objects_v2() | ||
.bucket("nara-national-archives-catalog") | ||
.delimiter("/") | ||
.prefix("authority-records/organization/") | ||
.max_keys(5); | ||
|
||
operation | ||
} | ||
|
||
// Test constructing an operation using an SdkConfig with a WASI http client | ||
// We do not send the request to keep these tests sandboxable, a full test of | ||
// the client is in the SDK canary. | ||
#[tokio::test] | ||
pub async fn test_operation_construction() { | ||
let operation = s3_list_objects_operation().await; | ||
assert_eq!( | ||
operation.get_bucket(), | ||
&Some("nara-national-archives-catalog".to_string()) | ||
); | ||
} |
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
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// Needed for WASI-compliant environment as it expects specific functions | ||
// to be exported such as `cabi_realloc`, `_start`, etc. | ||
|
||
wit_bindgen::generate!({ | ||
inline: " | ||
package aws:component; | ||
interface run { | ||
run: func() -> result; | ||
} | ||
world main { | ||
export run; | ||
} | ||
", | ||
exports: { | ||
"aws:component/run": Component | ||
} | ||
}); | ||
|
||
struct Component; | ||
|
||
impl exports::aws::component::run::Guest for Component { | ||
fn run() -> Result<(), ()> { | ||
Ok(()) | ||
} | ||
} |
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
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
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,29 @@ | ||
[package] | ||
name = "aws-smithy-wasm" | ||
version = "0.1.0" | ||
authors = [ | ||
"AWS Rust SDK Team <aws-sdk-rust@amazon.com>", | ||
"Eduardo Rodrigues <16357187+eduardomourar@users.noreply.github.com>", | ||
] | ||
description = "Smithy WebAssembly configuration for smithy-rs." | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/awslabs/smithy-rs" | ||
|
||
[dependencies] | ||
aws-smithy-runtime-api = { path = "../aws-smithy-runtime-api", features = ["http-1x"]} | ||
aws-smithy-http = { path = "../aws-smithy-http" } | ||
aws-smithy-types = { path = "../aws-smithy-types" } | ||
bytes = "1" | ||
http = "1.0.0" | ||
tracing = "0.1.40" | ||
# Note the wasi crate will only build for target wasm32-wasi, but having a target | ||
# statement here breaks some of the CI tests, so we leave it with the rest of the deps | ||
wasi = "0.12.0+wasi-0.2.0" | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] | ||
rustdoc-args = ["--cfg", "docsrs"] | ||
# End of docs.rs metadata |
Oops, something went wrong.