AWS Keyspace(Cassandra) api error


I have been trying to get a list of keyspaces name using cassandra api but it throws an error.


Error: <UnknownOperationException/> Status Code: 404

Note: AWS Access Credentials has all the admin permissions to perform the action.

asked a year ago406 views
1 Answer

If you mean you have configured AWS Access Credentials on your system by using the AWS cli to run aws configure, you can list Keyspaces with the command aws keyspaces list-keyspaces. You can also use an AWS SDK to list your keyspaces, such as the boto3 SDK for Python.

You appear to want to list keyspaces using the REST API, which is possible. You can use the API for data language definition (DDL) operations. This API reference describes the supported DDL operations in detail.

From there, you can find a list of supported Actions, including "ListKeyspaces"

But if you're not using the CLI or an SDK, you'll need to sign your requests manually, which is not trival.

Here is an example in Python

import json
import pprint
import urllib3

headers = {
    "X-Amz-Target": "KeyspacesService.ListKeyspaces",
    "Content-Type": "application/x-amz-json-1.0",
    "X-Amz-Date": "20230214T153319Z",
    "Authorization": f"AWS4-HMAC-SHA256 Credential={my_access_key}/20230214/us-east-2/cassandra/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature={my_signature}"

host = ""

http = urllib3.PoolManager()
r = http.request("POST", url=f"https://{host}", headers=headers)


Here it is with the Python boto3 client

import boto3

client = boto3.client(
    # endpoint_url='http://localhost:8000/',

response = client.list_keyspaces()

And if I swap-in localhost for the endpoint url and run a server locally to dump the headers, I can see these are the headers being sent to the Keyspaces API.

ERROR:root:Host: localhost:8000
Accept-Encoding: identity
X-Amz-Target: KeyspacesService.ListKeyspaces
Content-Type: application/x-amz-json-1.0
User-Agent: Boto3/1.26.70 Python/3.9.6 Darwin/21.6.0 Botocore/1.29.70
X-Amz-Date: 20230214T153319Z
Authorization: AWS4-HMAC-SHA256 Credential=<my_access_key>/20230214/us-east-2/cassandra/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=<my_signature>
amz-sdk-invocation-id: 20f45727-43a6-4f13-bbac-40502747a673
amz-sdk-request: attempt=5; max=5
Content-Length: 2
answered a year ago
  • Thank you for responding, Paul. I'll elaborate on the question. I've previously read those docs, and it works flawlessly with the AWS CLI and SDK, but not with the REST API. On referring to the following Document, this is the REST API: connected with AWS Keyspaces.

    However, when I try to hit it with the signed request, it fails and produces an error Error: UnknownOperationException/>. The status code is 404. (I've tried the same with RDS, RedShift, & DocumentDB, and everything works except the Cassandra API.)

  • Oh I see. I've posted a Python example in case it's useful? I saw the UnknownOperationException error until I added the X-Amz-Target header. Not sure if this will apply to you though. Otherwise I'm stumped. Good luck!

  • Thank you for your thoughts, Paul. I tested it using your Python code as well as Postman and encountered the same error.

  • Yeah my pleasure. I'm sorry we didn't get there. I'm posting the boto3 code and even the headers its sending above in case it helps anyone, including future me. Also this is the boto3 signing code for reference.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions