Create a keyspace in Amazon Keyspaces
In this section, you create a keyspace using the
console, cqlsh
, or the AWS CLI.
Note
Before you begin, make sure that you have configured all the tutorial prerequisites.
A keyspace groups related tables that are relevant for one or more applications. A keyspace contains one or more tables and defines the replication strategy for all the tables it contains. For more information about keyspaces, see the following topics:
Data definition language (DDL) statements in the CQL language reference: Keyspaces
In this tutorial we create a single-Region keyspace, and the replication strategy of
the keyspace is SingleRegionStrategy
. Using
SingleRegionStrategy
, Amazon Keyspaces replicates data across three Availability
Zones
To create a keyspace using the console
-
Sign in to the AWS Management Console, and open the Amazon Keyspaces console at https://console.aws.amazon.com/keyspaces/home
. -
In the navigation pane, choose Keyspaces.
-
Choose Create keyspace.
-
In the Keyspace name box, enter
catalog
as the name for your keyspace.Name constraints:
-
The name can't be empty.
-
Allowed characters: alphanumeric characters and underscore (
_
). -
Maximum length is 48 characters.
-
Under AWS Regions, confirm that Single-Region replication is the replication strategy for the keyspace.
-
To create the keyspace, choose Create keyspace.
-
Verify that the keyspace
catalog
was created by doing the following:-
In the navigation pane, choose Keyspaces.
-
Locate your keyspace
catalog
in the list of keyspaces.
-
The following procedure creates a keyspace using CQL.
To create a keyspace using CQL
Open AWS CloudShell and connect to Amazon Keyspaces using the following command. Make sure to update
us-east-1
with your own Region.cqlsh-expansion cassandra.
us-east-1
.amazonaws.com 9142 --sslThe output of that command should look like this.
Connected to Amazon Keyspaces at cassandra.us-east-1.amazonaws.com:9142 [cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh current consistency level is ONE.
-
Create your keyspace using the following CQL command.
CREATE KEYSPACE catalog WITH REPLICATION = {'class': 'SingleRegionStrategy'};
SingleRegionStrategy
uses a replication factor of three and replicates data across three AWS Availability Zones in its Region.Note
Amazon Keyspaces defaults all input to lowercase unless you enclose it in quotation marks.
-
Verify that your keyspace was created.
SELECT * from system_schema.keyspaces;
The output of this command should look similar to this.
cqlsh> SELECT * from system_schema.keyspaces; keyspace_name | durable_writes | replication -------------------------+----------------+------------------------------------------------------------------------------------- system_schema | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} system_schema_mcs | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} system | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} system_multiregion_info | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} catalog | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} (5 rows)
The following procedure creates a keyspace using the AWS CLI.
To create a keyspace using the AWS CLI
To confirm that your environment is setup, you can run the following command in CloudShell.
aws keyspaces help
-
Create your keyspace using the following AWS CLI statement.
aws keyspaces create-keyspace --keyspace-name 'catalog'
-
Verify that your keyspace was created with the following AWS CLI statement
aws keyspaces get-keyspace --keyspace-name 'catalog'
The output of this command should look similar to this example.
{ "keyspaceName": "catalog", "resourceArn": "arn:aws:cassandra:us-east-1:123SAMPLE012:/keyspace/catalog/", "replicationStrategy": "SINGLE_REGION" }