From 4920fb91eac221d8b5b4e54dd00116eb4909dd30 Mon Sep 17 00:00:00 2001 From: David Souther Date: Tue, 10 Oct 2023 17:11:07 -0400 Subject: [PATCH] Fix wasm connector --- rust_dev_preview/webassembly/Cargo.toml | 4 +-- rust_dev_preview/webassembly/src/lib.rs | 46 ++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/rust_dev_preview/webassembly/Cargo.toml b/rust_dev_preview/webassembly/Cargo.toml index 823f0744c69..f3661acd212 100644 --- a/rust_dev_preview/webassembly/Cargo.toml +++ b/rust_dev_preview/webassembly/Cargo.toml @@ -13,10 +13,11 @@ 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" @@ -24,7 +25,6 @@ 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" diff --git a/rust_dev_preview/webassembly/src/lib.rs b/rust_dev_preview/webassembly/src/lib.rs index b5c96affeb0..b5f22a54100 100644 --- a/rust_dev_preview/webassembly/src/lib.rs +++ b/rust_dev_preview/webassembly/src/lib.rs @@ -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}; @@ -63,7 +75,7 @@ pub async fn main(region: String, verbose: bool) -> Result { .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); @@ -234,24 +246,8 @@ impl Adapter { } } -impl tower::Service> for Adapter { - type Response = http::Response; - - type Error = ConnectorError; - - #[allow(clippy::type_complexity)] - type Future = std::pin::Pin< - Box> + Send + 'static>, - >; - - fn poll_ready( - &mut self, - _cx: &mut std::task::Context<'_>, - ) -> std::task::Poll> { - std::task::Poll::Ready(Ok(())) - } - - fn call(&mut self, req: http::Request) -> 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 { @@ -277,10 +273,20 @@ impl tower::Service> 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() + } +}