I'm having problems connecting to AWS Managed Cassandra Service from my Lagom environment. Here's what I have tried, with what results.
(1) Amazon provides instructions for connecting to AWS MCS from Java code:
https://docs.aws.amazon.com/fr_fr/mcs/latest/devguide/cqlsh.html#using_java_driver
The gist of the instructions is that you need to install a certificate and then pass it to the JVM as follows:
-Djavax.net.ssl.trustStore=path_to_file/cassandra_truststore.jks
-Djavax.net.ssl.trustStorePassword=amazon
Then, you can use any Cassandra Java drivers of your choice. And my choice is the DataStax drivers provided with the Lagom framework.
This I did by adding the following to build.sbt
:
javaOptions ++= Seq(
"-Djavax.net.ssl.trustStore=project/cassandra_truststore.jks",
"-Djavax.net.ssl.trustStorePassword=amazon"
)
// Must enable JVM forking to use javaOptions with runAll.
fork := true
(2) Before deploying my Lagom application to AWS, I want to work with it in Dev mode but connecting it to AWS MCS instead of the embedded Cassandra server. Lagom provides instructions for doing this in Dev mode:
The gist of the instructions is to add the following lines to build.sbt
:
lagomCassandraEnabled in ThisBuild := false
lagomUnmanagedServices in ThisBuild := Map("cas_native" -> "tcp://localhost:9042")
The URI in this example assumes a Cassandra server running on localhost:9042
. In my case, I substituted that with cassandra.us-east-1.amazonaws.com:9142
.
(3) Nevertheless, when I run sbt runAll
, I'm getting timeouts when trying to reach AWS MCS:
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: cassandra.us-east-1.amazonaws.com/3.83.168.143:9142 (com.datastax.driver.core.exceptions.OperationTimedOutException: [cassandra.us-east-1.amazonaws.com/3.83.168.143:9142] Operation timed out))
(4) I have isolated the problem by bypassing Lagom entirely and just writing a very simple piece of code, like this:
System.setProperty("javax.net.ssl.trustStore", "redacted_absolute_file_path/cassandra_truststore.jks")
System.setProperty("javax.net.ssl.trustStorePassword", "amazon")
val cluster = Cluster.builder.addContactPoint("cassandra.us-east-1.amazonaws.com").withPort(9142).build()
val session = cluster.connect()
session.close()
cluster.close()
This is as simple as it gets. But the same timeout occurs. What am I doing wrong?
Found a solution by looking at the AWS MCS Python documentation (the Java documentation is conspicuously silent on the matter). Turns out I do need to configure MCS service-specific credentials and then provide them in the Lagom's application.conf
file as follows:
cassandra.default {
port = 9142
ssl.truststore {
path = "path/cassandra_truststore.jks"
password = "amazon"
}
authentication {
username = "service-specific username"
password = "service-specific password"
}
}
cassandra-journal {
port = ${cassandra.default.port}
ssl.truststore {
path = ${cassandra.default.ssl.truststore.path}
password = ${cassandra.default.ssl.truststore.password}
}
authentication {
username = ${cassandra.default.authentication.username}
password = ${cassandra.default.authentication.password}
}
}
cassandra-snapshot-store {
port = ${cassandra.default.port}
ssl.truststore {
path = ${cassandra.default.ssl.truststore.path}
password = ${cassandra.default.ssl.truststore.password}
}
authentication {
username = ${cassandra.default.authentication.username}
password = ${cassandra.default.authentication.password}
}
}
lagom.persistence.read-side.cassandra {
port = ${cassandra.default.port}
ssl.truststore {
path = ${cassandra.default.ssl.truststore.path}
password = ${cassandra.default.ssl.truststore.password}
}
authentication {
username = ${cassandra.default.authentication.username}
password = ${cassandra.default.authentication.password}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.