AmazonWebServiceClient should have a toBuilder method
Currently we have a use case where we are saving a client for reuse and sometimes change its endpoint. Because setEndpoint is deprecated in favour of builder, we cannot provide such a use case. Would you consider supporting a method such as AmazonEC2Client.toBuilder().withEndpointConfiguration() to support copying existing properties, then change select properties? ` class ClientProvider {
private AmazonEC2Client ec2Client;
public ClientProvider(AmazonEC2Client ec2Client) {
this.ec2Client = ec2Client;
}
public AmazonEC2Client getEc2Client() {
return ec2Client;
}
public void setEndpoint(String endpoint) {
if(ec2Client != null) {
ec2Client.setEndpoint(endpoint);
}
}
} `
Describe the Feature
Is your Feature Request related to a problem?
Proposed Solution
Describe alternatives you've considered
Additional Context
Your Environment
- AWS Java SDK version used:
- JDK version used:
- Operating System and version:
A copy constructor in builder, as suggested in https://github.com/aws/aws-sdk-java/issues/1067, would be appropriate as well, but I don't see this feature right now.
Hi @blitz555, as mentioned in #1067 it was a change we decided not to make in v1. Since the focus of the team work is in new features for SDK v2, this change would have low priority too.
Maybe having a Client Factory would fit your use case?
@debora-ito Hi, thank you for your continued support with my questions. I attempted to save reference of the client factory in lieu of a copy constructor, in place of the client in code sample. Previously, out Client provider class used client constructors, and .setRegion and .setEndpoint after creation of client. This worked fine until I switched to using builder.withRegion and builder.withEndpointConfiguration as recommended by documentation. However, now that I ran a functional test on a code path that may have called both .withRegion (first) and .withEndpointConfiguration (second), I encountered the following error,
java.lang.IllegalStateException: Only one of Region or EndpointConfiguration may be set. at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:450) at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:424) at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
Have I used a forbidden use case that I haven't read about and shouldn't be using? Is there a way for me to check if builder.withRegion is already called before calling builder.withEndpointConfiguration? Is there a way to override the .withRegion call with a subsequent .withEndpointConfiguration call?