I’ve a simple crud based application in which Apache Cassandra is used as the default database. I’ve used Spring Data Cassandra for the Cassandra connectivity.
Now, I’m trying to move into AWS Keyspace which which is well supported with the Cassandra java driver. I’ve followed this doc for the configuration.
However, I’m always getting the following exception whenever I’m starting the app.
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: cassandra.us-east-2.amazonaws.com/<ip>:9142 (com.datastax.driver.core.exceptions.OperationTimedOutException: [cassandra.us-east-2.amazonaws.com/<ip>:9142] Operation timed out))
I’ve used added following props in the application.properties:
spring.data.cassandra.contact-points=cassandra.us-east-2.amazonaws.com
spring.data.cassandra.port=9142
spring.data.cassandra.cluster-name=<name>
spring.data.cassandra.username=<username>
spring.data.cassandra.password=<password>
I’ve also tried using application.conf by adding the props:
datastax-java-driver {
basic.contact-points = [ "cassandra.us-east-2.amazonaws.com:9142"]
advanced.auth-provider{
class = PlainTextAuthProvider
username = "<username>"
password = "<password>"
}
basic.load-balancing-policy {
local-datacenter = "us-east-2"
}
advanced.ssl-engine-factory {
class = DefaultSslEngineFactory
truststore-path = "/home/centos/keyspaces/cassandra_truststore.jks"
truststore-password = "<password>"
}
}
But still same result. Note that the trustStore config is added as jvm argumets as well:
javax.net.ssl.trustStore=/home/centos/keyspaces/cassandra_truststore.jks
javax.net.ssl.trustStorePassword=<password>
Strange thing is that, from the same machine I can telnet to this Keyspace host-port and even can directly connect to that instance using below command:
conda activate python2
export SSL_CERTFILE="/home/centos/keyspaces/sf-class2-root.crt"
cqlsh cassandra.us-east-2.amazonaws.com 9142 -u <username> -p <password> --ssl
2
Answers
I’m sorry your having a hard time connecting. The error you posted makes me think something isn’t connecting properly.
This is a github page that has a code sample on how to connect to Amazon Keypspaces using the Spring Data for Cassandra: https://github.com/aws-samples/amazon-keyspaces-spring-app-example/blob/main/src/main/java/com/aws/mcs/springsample/KeyspacesSpringApplication.java
It actually looks like the query/operation timed out and not connections. This is usually related to exceeding capacity. I would suggest setting up observability for your tables. The following repository will setup table and keyspace cloudwatch metrics using cloudformation. This will provide you will more visibility into your capacity.
https://github.com/aws-samples/amazon-keyspaces-cloudwatch-cloudformation-templates