Skip to content

Commit 4920fb9

Browse files
DavidSoutherford-at-aws
authored andcommitted
Fix wasm connector
1 parent 5f83d6d commit 4920fb9

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

rust_dev_preview/webassembly/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ crate-type = ["cdylib"]
1313
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", default-features = false }
1414
aws-credential-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["hardcoded-credentials"] }
1515
aws-sdk-lambda = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", default-features = false }
16+
aws-smithy-async = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
1617
aws-smithy-client = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", default-features = false }
1718
aws-smithy-http = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["event-stream"] }
19+
aws-smithy-runtime-api = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
1820
aws-smithy-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
19-
aws-smithy-async = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
2021
async-trait = "0.1.63"
2122
console_error_panic_hook = "0.1.7"
2223
http = "0.2.8"
2324
js-sys = "0.3.60"
2425
serde = { version = "1.0.152", features = ["derive"] }
2526
serde-wasm-bindgen = "0.4.5"
2627
tokio = { version = "1.24.2", features = ["macros", "rt"] }
27-
tower = "0.4.13"
2828
wasm-bindgen = "0.2.83"
2929
wasm-bindgen-futures = "0.4.33"
3030
wasm-timer = "0.2.5"

rust_dev_preview/webassembly/src/lib.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ use aws_sdk_lambda::primitives::SdkBody;
1010
use aws_sdk_lambda::{meta::PKG_VERSION, Client};
1111
use aws_smithy_async::time::TimeSource;
1212
use aws_smithy_http::result::ConnectorError;
13+
use aws_smithy_runtime_api::{
14+
client::{
15+
http::{
16+
HttpClient, HttpConnector, HttpConnectorFuture, HttpConnectorSettings,
17+
SharedHttpConnector,
18+
},
19+
orchestrator::HttpRequest,
20+
runtime_components::RuntimeComponents,
21+
},
22+
shared::IntoShared,
23+
};
24+
1325
use serde::Deserialize;
1426
use std::time::SystemTime;
1527
use wasm_bindgen::{prelude::*, JsCast};
@@ -63,7 +75,7 @@ pub async fn main(region: String, verbose: bool) -> Result<String, String> {
6375
.region(Region::new(region))
6476
.time_source(BrowserNow)
6577
.credentials_provider(credentials_provider)
66-
.http_connector(Adapter::new(verbose, access_key == "access_key"))
78+
.http_client(Adapter::new(verbose, access_key == "access_key"))
6779
.load()
6880
.await;
6981
tracing::info!("sdk config: {:#?}", shared_config);
@@ -234,24 +246,8 @@ impl Adapter {
234246
}
235247
}
236248

237-
impl tower::Service<http::Request<SdkBody>> for Adapter {
238-
type Response = http::Response<SdkBody>;
239-
240-
type Error = ConnectorError;
241-
242-
#[allow(clippy::type_complexity)]
243-
type Future = std::pin::Pin<
244-
Box<dyn std::future::Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>,
245-
>;
246-
247-
fn poll_ready(
248-
&mut self,
249-
_cx: &mut std::task::Context<'_>,
250-
) -> std::task::Poll<Result<(), Self::Error>> {
251-
std::task::Poll::Ready(Ok(()))
252-
}
253-
254-
fn call(&mut self, req: http::Request<SdkBody>) -> Self::Future {
249+
impl HttpConnector for Adapter {
250+
fn call(&self, req: HttpRequest) -> HttpConnectorFuture {
255251
let (parts, body) = req.into_parts();
256252
let uri = parts.uri.to_string();
257253
if self.verbose {
@@ -277,10 +273,20 @@ impl tower::Service<http::Request<SdkBody>> for Adapter {
277273
);
278274
});
279275

280-
Box::pin(async move {
276+
HttpConnectorFuture::new(async move {
281277
let response = rx.await.map_err(|e| ConnectorError::user(Box::new(e)))?;
282278
log!("response received");
283279
Ok(response)
284280
})
285281
}
286282
}
283+
284+
impl HttpClient for Adapter {
285+
fn http_connector(
286+
&self,
287+
_settings: &HttpConnectorSettings,
288+
_components: &RuntimeComponents,
289+
) -> SharedHttpConnector {
290+
self.clone().into_shared()
291+
}
292+
}

0 commit comments

Comments
 (0)