Amazon Keyspaces

Hands-On

Demo

In this demo, we will:

  1. Set up security credentials for programmatic access

  2. Create a keyspace using the AWS Management Console

  3. Create a table with appropriate schema design

  4. Connect using AWS CloudShell and cqlsh-expansion

  5. Perform CRUD operations (Create, Read, Update, Delete)

  6. Enable and test Point-in-Time Recovery (PITR)

  7. Clean up resources

Agenda

keyspaces-user

Create user

Set permissions

Review and create

Credentials for Amazon Keyspaces (for Apache Cassandra)

Credentials

Amazon Keyspaces

ecommerce_system

Create keyspace

Create keyspace

Create table

order_details

Create table

customer_id
uuid
order_date
date
order_id
uuid
product_name
text
quantity
int
unit_price
decimal
order_status
text

Primary key

order_date
DESC
order_id
ASC

Table settings

Point-in-time recovery: Leave Disabled for now (we'll enable this later)

Other Settings 

Table tags

Create table

order_details

AWS CloudShell

wget https://www.amazontrust.com/repository/AmazonRootCA1.pem -O ~/AmazonRootCA1.pem
ls -l ~/AmazonRootCA1.pem
echo -e "[ssl]\ncertfile = /home/cloudshell-user/AmazonRootCA1.pem" > ~/.cassandra/cqlshrc
cat ~/.cassandra/cqlshrc
cqlsh-expansion cassandra.us-east-1.amazonaws.com 9142 --ssl -u 

Add Permissions to User

AmazonKeyspacesFullAccess

Add permissions

Review

keyspaces-user

Login Successful

SELECT * FROM system_schema.keyspaces;
USE ecommerce_system;
DESCRIBE TABLE order_details;
-- Set consistency level for writes
CONSISTENCY LOCAL_QUORUM;

-- Insert sample order data
INSERT INTO order_details (customer_id, order_date, order_id, product_name, quantity, unit_price, order_status)
VALUES (uuid(), '2024-01-15', uuid(), 'Wireless Headphones', 2, 99.99, 'shipped');

INSERT INTO order_details (customer_id, order_date, order_id, product_name, quantity, unit_price, order_status)
VALUES (uuid(), '2024-01-14', uuid(), 'Bluetooth Speaker', 1, 149.99, 'delivered');

INSERT INTO order_details (customer_id, order_date, order_id, product_name, quantity, unit_price, order_status)
VALUES (uuid(), '2024-01-13', uuid(), 'Gaming Mouse', 3, 79.99, 'processing');

-- Insert multiple orders for the same customer
INSERT INTO order_details (customer_id, order_date, order_id, product_name, quantity, unit_price, order_status)
VALUES (550e8400-e29b-41d4-a716-446655440000, '2024-01-12', uuid(), 'Mechanical Keyboard', 1, 129.99, 'delivered');

INSERT INTO order_details (customer_id, order_date, order_id, product_name, quantity, unit_price, order_status)
VALUES (550e8400-e29b-41d4-a716-446655440000, '2024-01-10', uuid(), 'USB-C Hub', 2, 49.99, 'shipped');
-- Read all order details (limited for performance)
SELECT * FROM order_details LIMIT 10;
-- Read orders for a specific customer (efficient query using partition key)
SELECT * FROM order_details 
WHERE customer_id = 550e8400-e29b-41d4-a716-446655440000;
-- Read orders within a date range for a customer
SELECT * FROM order_details 
WHERE customer_id = 550e8400-e29b-41d4-a716-446655440000 
AND order_date >= '2024-01-01' 
AND order_date <= '2024-01-31';
-- Update order status (you'll need to use actual UUIDs from your data)
UPDATE order_details 
SET order_status = 'delivered'
WHERE customer_id = 550e8400-e29b-41d4-a716-446655440000 
AND order_date = '2024-01-10' 
AND order_id = [use_actual_order_id_from_your_data];
-- Update quantity and unit price
UPDATE order_details 
SET quantity = 5, unit_price = 45.99
WHERE customer_id = 550e8400-e29b-41d4-a716-446655440000 
AND order_date = '2024-01-10' 
AND order_id = [use_actual_order_id_from_your_data];
-- Delete a specific order
DELETE FROM order_details 
WHERE customer_id = 550e8400-e29b-41d4-a716-446655440000 
AND order_date = '2024-01-10' 
AND order_id = [use_actual_order_id_from_your_data];
-- Delete all orders for a customer on a specific date
DELETE FROM order_details 
WHERE customer_id = 550e8400-e29b-41d4-a716-446655440000 
AND order_date = '2024-01-12';

Enable and Test Point-in-Time Recovery (PITR)

Turn on Point-in-time-recovery

INSERT INTO order_details (customer_id, order_date, order_id, product_name, quantity, unit_price, order_status)
VALUES (uuid(), '2024-01-16', uuid(), 'Test Product for PITR', 1, 1.00, 'test');
SELECT * FROM order_details WHERE product_name = 'Test Product for PITR' ALLOW FILTERING;
DELETE FROM order_details
WHERE customer_id = ;

Wait 5 minutes, then delete the test record.

 

Note the current time before deleting.

Restore Using PITR (Console Method)

order_details_restored

Restore to a point in time

cqlsh-expansion cassandra.us-east-1.amazonaws.com 9142 --ssl -u 

Test PITR

USE ecommerce_system;
SELECT * FROM order_details_restored;

Delete Tables

-- Connect to cqlsh if not already connected
USE ecommerce_system;

-- Drop the restored table
DROP TABLE order_details_restored;

-- Drop the main table
DROP TABLE order_details;

-- Drop the entire keyspace
DROP KEYSPACE ecommerce_system;

Delete keyspace

Delete keyspace

Delete

Confirm

Delete IAM User

confirm

🙏

Thanks

for

Watching