Redirect AWS sdks' default endpoint to mocked localstack endpoints Redirect AWS sdks' default endpoint to mocked localstack endpoints docker docker

Redirect AWS sdks' default endpoint to mocked localstack endpoints


Ok, I was able to finally find a solution for this. I had to actually go through localstack code base to be able to find the solution. Couple of quick things :

  • Localstack is not integrated with IAM. So it just simply ignores the secret key or password.
  • If you're using IAM, you now need to have a flag to override the endpoint. You can probably have a flag to indicate localstack mode.

Couple of classes which I found helpful if you're debugging issues :
https://github.com/atlassian/localstack/blob/master/localstack/ext/java/src/test/java/com/atlassian/localstack/SQSMessagingTest.javahttps://github.com/atlassian/localstack/blob/master/localstack/ext/java/src/test/java/com/atlassian/localstack/TestUtils.java

Now for the solution :

AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration("http://localhost:4576/", awsRegion.getName());    AmazonSQSClient client =  (AmazonSQSClient) AmazonSQSClientBuilder.standard()        .withCredentials(configuration.getSqsConfiguration().getCredentialsProvider())        .withEndpointConfiguration(endpoint)        .build();

Here http://localhost:4576/ is where localstacks runs SQS. Don't miss the trailing slash. For using this in camel route is same as using AWS resources. Hopefully this helps!