You will have to connect your Kinesis and DynamoDB client to localstak.
For this you will need the edgePort of localStack , Host Name . and form a Local Stack edge port URL . Here how it should be
public class public class Host {
private static final String LOCAL = "localhost";
public static final String DOCKER = "docker-desktop";
public String getName(){
ProcessBuilder processBuilder =
new ProcessBuilder()
.command("docker", "run", "--net", "host", "bash", "-c", "hostname", "-I");
String hostname = null;
try {
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
hostname = reader.readLine().strip();
int exitVal = process.waitFor();
} catch (Exception e) {
// log for exception
}
if (DOCKER.equals(hostname)) {
return LOCAL_HOST;
} else {
return hostname;
}
}
}
now you need to get the host name and create URL something like this .
String localStackUrl =
String.format("http://%s:%s", new Host().getName(), edgePort);
and then create clients as follows
SdkHttpClient httpClient = ApacheHttpClient.builder()
.maxConnections(50)
.build();
KinesisAsyncClient client =
KinesisAsyncClient.builder()
.region(Region.of(Localstack.getDefaultRegion()))
.httpClient(httpClient)
.credentialsProvider(provider)
.endpointOverride(new URI(localStackUrl))
.build();
DynamoDbAsyncClient dynamoClient =
DynamoDbAsyncClient.builder()
.region(Region.of(Localstack.getDefaultRegion()))
.httpClient(httpClient)
.credentialsProvider(provider)
.endpointOverride(new URI(localStackUrl))
.build();