-
If I make M (potentially a million+) clients of smithy sdks, each with potentially different credentials or other config values, how can I optionally get them to share the same underlying HTTP client to avoid M clients being created each with their own duplicate cert chains and other cruft? Is this the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
There's no built-in support for sharing connectors currently, but it is possible to do it manually. To share the connector between clients, you would need to use the A connector needs to implement the I think you'll have to do something like this: #[derive(Clone)]
struct SharedConnector<I> {
inner: /* some shareable type here, such as Arc<Mutex<I>> */
}
impl<I> SharedConnector<I> {
fn new(inner: I) -> Self { Self { inner } }
}
impl<I> Service<Request<SdkBody>> for SharedConnector<I>
where
I: Service<Request<SdkBody>, Response = Response<SdkBody>>,
I::Error: Into<ConnectorError> + Send + Sync + 'static,
I::Future: Send + 'static,
{
type Response = Response<SdkBody>;
type Error = I::Error;
type Future = I::Future;
fn poll_ready(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), Self::Error>> {
// Defer to `inner` (needs some tweaking depending on synchronization chosen):
self.inner.poll_ready(cx)
}
fn call(&mut self, req: http::Request<SdkBody>) -> Self::Future {
// Defer to `inner` (needs some tweaking depending on synchronization chosen):
self.inner.call(req)
}
} You'll have to decide how to share the underlying connector stored in Ultimately, you should be able to do something like this: let shared_connector = SharedConnector::new(aws_smithy_client::conn::https());
let client1 = Builder::new().connector(shared_connector.clone()).middleware(...).build();
let client2 = Builder::new().connector(shared_connector.clone()).middleware(...).build(); |
Beta Was this translation helpful? Give feedback.
-
I just wanted to follow up on this— So there will be only one certificate chain created as it is with Rustls—if you're seeing different behavior please let us know! |
Beta Was this translation helpful? Give feedback.
There's no built-in support for sharing connectors currently, but it is possible to do it manually.
To share the connector between clients, you would need to use the
connector()
function on theBuilder
, and give it some kind of shared connector implementation. The built-inDynConnector
calls theClone
implementation of whatever is inside of it.A connector needs to implement the
SmithyConnector
trait, which is automatically implemented for anything that respects these bounds.I think you'll have to do something like this: