Currently there is no way to set proxy as ClientInner is private and cannot be mutated. Its a very common practice to use proxy in aws environment as most enterprises use private VPCs.
I haven't had a chance to play with proxies much. Some instructions on how to set up an environment with a proxy would be nice. Would squid work for that?
This should be possible with Rusoto today.
Essentially, you can construct a request dispatcher via the HttpClient::from_connector constructor.
This connector needs to be an impl of hyper::client::Connect. There are packages like hyper-proxy that give you an impl of Connect (e.g. hyper_proxy::ProxyConnector) which supports connecting to an http/https proxy.
Once you have an instance of HttpClient, you can then use it with any ::new_with constructor that Rusoto offers you (e.g. S3Client::new_with).
Hope that helps!
This certainly isn't tidy enough for a demo, but I just put this together to work through a very specific use-case and it works fine. Just in case someone is looking for an example..
use hyper::client::HttpConnector;
use hyper_proxy::{Proxy, ProxyConnector, Intercept};
use rusoto_core::request::HttpClient;
use rusoto_core::credential::ChainProvider;
let client = match env::var("HTTPS_PROXY") {
Ok(proxy_uri) => {
let proxy = Proxy::new(Intercept::All, proxy_uri.parse()?);
let proxy_connector = ProxyConnector::from_proxy(
HttpConnector::new(4), proxy
)?;
let http = HttpClient::from_connector(proxy_connector);
S3Client::new_with(http, ChainProvider::new(), region)
},
Err(_) => S3Client::new(region)
};
Thanks for the example, @ccakes ! Since we have a ticket for documenting this on https://rusoto.org I think we can close this.
Please reopen if there's still issues!
Hello,
It seems that the example above is no longer possible due to rusoto updates.
Is there an updated example somewhere ?
Thanks !
@Wykiki I just took @ccakes example and wrapped it in a macro:
use rusoto_dynamodb::{DynamoDb, DynamoDbClient, ListTablesInput};
macro_rules! aws_client {
($client:ty) => {{
use hyper::client::HttpConnector;
use hyper_proxy::{Intercept, Proxy, ProxyConnector};
use rusoto_core::credential::ChainProvider;
use rusoto_core::request::HttpClient;
use rusoto_core::Region;
use std::env;
match env::var("HTTPS_PROXY") {
Ok(proxy_uri) => {
let proxy = Proxy::new(
Intercept::All,
proxy_uri.parse().expect("HTTPS_PROXY format is invalid"),
);
let proxy_connector = ProxyConnector::from_proxy(HttpConnector::new(), proxy)
.expect("failed to create proxy connector");
let http = HttpClient::from_connector(proxy_connector);
<$client>::new_with(http, ChainProvider::new(), Region::default())
}
Err(_) => <$client>::new(Region::default()),
}
}};
}
#[tokio::main]
async fn main() {
let dynamo_client = aws_client!(DynamoDbClient);
let list_tables_input = ListTablesInput::default();
...
}
Most helpful comment
This certainly isn't tidy enough for a demo, but I just put this together to work through a very specific use-case and it works fine. Just in case someone is looking for an example..