Amit Nanda
Amit Nanda

Reputation: 41

How to connect AWS Keyspace using Django Cassandra Engine?

I am trying to set a django app and connect it to AWS Keyspaces. Trying to do it using django-cassandra-engine.

I'm currently using this setup in the settings, but it's not working.

    ssl_context = SSLContext(PROTOCOL_TLSv1_2)
    ssl_context.load_verify_locations('/Users/amit/sf-class2-root.crt')
    ssl_context.verify_mode = CERT_REQUIRED

DATABASES = {
    'default': {
        'ENGINE': 'django_cassandra_engine',
        'NAME': 'Keyspace Name',
        'HOST': 'Cluster()',
        'connection': {
            'port': 9142,
            'contact_points': ['cassandra.us-east-1.amazonaws.com'],
            'ssl_context': ssl_context,
            'auth_provider': PlainTextAuthProvider(username='USERNAME',password='PASSWORD')

        }
    }
}

Error:

 File "/Users/amit/workspace/eventHandler/venv/lib/python3.9/site-packages/django_cassandra_engine/connection.py", line 78, in register
connection.get_connection(name=self.alias)

File "/Users/amit/workspace/eventHandler/venv/lib/python3.9/site-packages/cassandra/cqlengine/connection.py", line 247, in get_connection raise CQLEngineException("Connection name '{0}' doesn't exist in the registry.".format(name)) cassandra.cqlengine.CQLEngineException: Connection name 'default' doesn't exist in the registry.

Upvotes: 1

Views: 481

Answers (2)

Amit Nanda
Amit Nanda

Reputation: 41

Figured out:-

DATABASES = {
'default': {
    'ENGINE': 'django_cassandra_engine',
    'NAME': 'KEYSPACE_NAME',
    'HOST': 'cassandra.us-east-1.amazonaws.com',
    'OPTIONS': {
        'replication': {
            'strategy_class': 'SimpleStrategy',
            'replication_factor': 1
        },
        'connection': {
            'port': 9142,
            'ssl_context': ssl_context,
            'auth_provider': PlainTextAuthProvider(username='USERNAME',
                                                   password='PASSWORD')

        }

    }
}

}

Upvotes: 1

Maurice
Maurice

Reputation: 13177

I haven't used Keyspaces or Cassandra, but from looking at the endpoint documentation and python examples in AWS, I'm guessing that the port should be 9142 instead of 9042.

Upvotes: 0

Related Questions