Skip to content

Commit

Permalink
Fix wasm connector
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored and ford-at-aws committed Oct 11, 2023
1 parent 5f83d6d commit 4920fb9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions rust_dev_preview/webassembly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ crate-type = ["cdylib"]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", default-features = false }
aws-credential-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["hardcoded-credentials"] }
aws-sdk-lambda = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", default-features = false }
aws-smithy-async = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-smithy-client = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", default-features = false }
aws-smithy-http = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["event-stream"] }
aws-smithy-runtime-api = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-smithy-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-smithy-async = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
async-trait = "0.1.63"
console_error_panic_hook = "0.1.7"
http = "0.2.8"
js-sys = "0.3.60"
serde = { version = "1.0.152", features = ["derive"] }
serde-wasm-bindgen = "0.4.5"
tokio = { version = "1.24.2", features = ["macros", "rt"] }
tower = "0.4.13"
wasm-bindgen = "0.2.83"
wasm-bindgen-futures = "0.4.33"
wasm-timer = "0.2.5"
Expand Down
46 changes: 26 additions & 20 deletions rust_dev_preview/webassembly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ use aws_sdk_lambda::primitives::SdkBody;
use aws_sdk_lambda::{meta::PKG_VERSION, Client};
use aws_smithy_async::time::TimeSource;
use aws_smithy_http::result::ConnectorError;
use aws_smithy_runtime_api::{
client::{
http::{
HttpClient, HttpConnector, HttpConnectorFuture, HttpConnectorSettings,
SharedHttpConnector,
},
orchestrator::HttpRequest,
runtime_components::RuntimeComponents,
},
shared::IntoShared,
};

use serde::Deserialize;
use std::time::SystemTime;
use wasm_bindgen::{prelude::*, JsCast};
Expand Down Expand Up @@ -63,7 +75,7 @@ pub async fn main(region: String, verbose: bool) -> Result<String, String> {
.region(Region::new(region))
.time_source(BrowserNow)
.credentials_provider(credentials_provider)
.http_connector(Adapter::new(verbose, access_key == "access_key"))
.http_client(Adapter::new(verbose, access_key == "access_key"))
.load()
.await;
tracing::info!("sdk config: {:#?}", shared_config);
Expand Down Expand Up @@ -234,24 +246,8 @@ impl Adapter {
}
}

impl tower::Service<http::Request<SdkBody>> for Adapter {
type Response = http::Response<SdkBody>;

type Error = ConnectorError;

#[allow(clippy::type_complexity)]
type Future = std::pin::Pin<
Box<dyn std::future::Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>,
>;

fn poll_ready(
&mut self,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), Self::Error>> {
std::task::Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<SdkBody>) -> Self::Future {
impl HttpConnector for Adapter {
fn call(&self, req: HttpRequest) -> HttpConnectorFuture {
let (parts, body) = req.into_parts();
let uri = parts.uri.to_string();
if self.verbose {
Expand All @@ -277,10 +273,20 @@ impl tower::Service<http::Request<SdkBody>> for Adapter {
);
});

Box::pin(async move {
HttpConnectorFuture::new(async move {
let response = rx.await.map_err(|e| ConnectorError::user(Box::new(e)))?;
log!("response received");
Ok(response)
})
}
}

impl HttpClient for Adapter {
fn http_connector(
&self,
_settings: &HttpConnectorSettings,
_components: &RuntimeComponents,
) -> SharedHttpConnector {
self.clone().into_shared()
}
}

0 comments on commit 4920fb9

Please sign in to comment.