Skip to content

Instantly share code, notes, and snippets.

@netstart
Last active March 12, 2019 21:34
Show Gist options
  • Save netstart/d666f617196c45c826cfae298664deaf to your computer and use it in GitHub Desktop.
Save netstart/d666f617196c45c826cfae298664deaf to your computer and use it in GitHub Desktop.
Trick to build AsyncClient for AWS services in LocalStack
import java.util.function.Supplier;
import cloud.localstack.TestUtils;
import cloud.localstack.docker.LocalstackDocker;
public class TestAsyncUtils extends TestUtils {
public static AmazonDynamoDBAsync getClientDynamoDBAsync() {
return AmazonDynamoDBAsyncClientBuilder.standard()
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointDynamoDB))
.withCredentials(getCredentialsProvider())
.build();
}
public static AmazonSQSAsync getClientSQSAsync() {
return getClientSQSAsync(null);
}
public static AmazonSQSAsync getClientSQSAsync(final ExecutorFactory executorFactory) {
return AmazonSQSAsyncClientBuilder.standard()
.withEndpointConfiguration(getEndpointConfigurationSQS())
.withExecutorFactory(executorFactory)
.withCredentials(getCredentialsProvider())
.build();
}
protected static AwsClientBuilder.EndpointConfiguration createEndpointConfiguration(Supplier<String> supplier) {
return getEndpointConfiguration(supplier.get());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment