I’m using the localstack testcontainer to mock the KMS calls from my application. The existing code in my app uses only the region, and it works fine when communicating with AWS.
But when I use the localstack params to the builder object, it still calls AWS -
https://kms.us-east-1.amazonaws.com/ which is failing with an invalid client exception.
However when i use the endpoint config builder method instead of region , it makes the call to localstack and works fine.
Do you know why when region and credentials alone are given, it makes the call to AWS? The AWSKMSClientBuilder doesn’t allow to use of both region and endpointconfiguration in the same builder object. Is there any workaround for this, other than using the withEndpointConfiguration instead of region?
Any help is appreciated. Thanks in advance!
Please have a look at our documentation for Java SDK | Docs (localstack.cloud)
Thanks for reporting @rps310 . Can you please share the version of the AWS SDK you’re using - looks like it is v1 (and not v2).
The client creation looks pretty similar to what we have in our Java utils repository here - maybe that helps as a starting point to find out more: https://github.com/localstack/localstack-java-utils/blob/master/src/main/java/cloud/localstack/awssdkv1/TestUtils.java#L210-L214
Also, can you please share what is the type of the
localstack object in your sample, and what the runtime values of
@whummer Im using the v1 SDK. The type of localstack im trying to create is AWS KMS.
public static LocalStackContainer localstack = new LocalStackContainer().withServices(LocalStackContainer.Service.KMS);
The runtime value of
localstack.getEndpoint().toString() changes for every run. It uses the port of the test container that gets created. The value of localstack.getRegion() is defaulted to us-east-1.
The only difference is im using region instead of withEndpointConfiguration. Looks like the aws sdk uses the default url unless it is overridden.
Thanks for confirming @rps310
Sorry, I may have misread your first message:
Do you know why when region and credentials alone are given, it makes the call to AWS? … Is there any workaround for this, other than using the withEndpointConfiguration instead of region?
Unfortunately not - currently it is required to set the endpoint configuration directly for each client. This is the expected behavior, as the AWS Java SDK does not allow global endpoint configurations (yet).
Please note that AWS has introduced custom endpoints recently, configurable via
AWS_ENDPOINT_URL: Service-specific endpoints - AWS SDKs and Tools Unfortunately, they are not yet supported in the Java SDK (see page bottom), but in the future it will become easier to make this configuration
Thanks for the confirmation @whummer !