【发布时间】:2021-01-05 11:18:57
【问题描述】:
我正在处理一个项目,现在我们请求为所有实例(Ec2、S3 等...)提供使 coll 认为是代理服务器的选项。 例如,我有:
AmazonElasticLoadBalancing elbClient = AmazonElasticLoadBalancingClientBuilder.standard() .withRegion(region.getName()).withCredentials(credentials).build();
AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard().withRegion(region).withCredentials(getCredentials()).build();
在我项目的很多地方。
检查 AWS Java SDK 文档后,我发现我需要在使用 build() 之前添加 withClientConfiguration(someMethodToGetProxyConfig())。
我对 java 还是很陌生,我很难创建一个足够通用的函数来为所有这些类型的客户端执行此操作。 我试过了:
public static AwsClientBuilder clientBuilder(AwsClientBuilder client) throws ServiceWareException {
final String PROXY = "proxy_host_port";
String hasProxy = Configuration.getConfigurationParameter(PROXY);
client = client.withRegion(getRegion()).withCredentials(getCredentials());
if (!hasProxy.isEmpty() && hasProxy != null)
client = client.withClientConfiguration(getProxyConfig());
return (AwsClientBuilder) client.build();
}
但它失败了,因为我无法将 AmazonEC2ClientBuilder 转换为 AwsClientBuilder。 有人可以分享一些关于如何做到这一点的提示,或者可能有做过类似事情的经验吗?
【问题讨论】:
标签: java amazon-web-services aws-sdk