Works with v1.10+
This recipe demonstrates how to configure a Spice dataset to stream real-time changes from an AWS-hosted DynamoDB table using DynamoDB Streams. You'll see how inserts, updates, and deletes automatically flow into Spice.
- An AWS account
- AWS CLI installed (installation guide)
- IAM user or role with DynamoDB permissions:
dynamodb:ListTables,dynamodb:DescribeTable,dynamodb:Scan,dynamodb:GetItem,dynamodb:Query,dynamodb:DescribeStream,dynamodb:GetShardIterator, anddynamodb:GetRecords - Spice.ai runtime (Getting Started)
git clone https://github.com/spiceai/cookbook.git
cd cookbook/dynamodb/streamsexport AWS_REGION=<your-region>Create a simple table with DynamoDB Streams enabled to capture all changes:
aws dynamodb create-table \
--table-name orders \
--attribute-definitions AttributeName=id,AttributeType=S \
--key-schema AttributeName=id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
--region $AWS_REGION
aws dynamodb put-item --table-name orders --item \
'{"id": {"S": "order-001"}, "customer": {"S": "Alice"}, "amount": {"N": "99.99"}, "status": {"S": "pending"}}' \
--region $AWS_REGIONUpdate the .env file with your AWS credentials:
SPICE_DYNAMODB_KEY=<aws_access_key_id>
SPICE_DYNAMODB_SECRET=<aws_secret_access_key>spice runYou should see the dataset initialize and begin streaming:
INFO runtime::init::dataset: Dataset orders_stream registered (dynamodb:orders), acceleration (duckdb:file, changes), results cache enabled.
INFO runtime::dataconnector::dynamodb: No existing checkpoint found for table orders_stream, starting from bootstrap
INFO runtime::dataconnector::dynamodb: Bootstrapping DynamoDB table orders_stream, records=1
INFO runtime::dataconnector::dynamodb: Bootstrapping DynamoDB table orders_stream complete, starting changes stream. Table will be marked as Ready once stream lag reaches < '1h'
INFO runtime: All components are loaded. Spice runtime is ready!In the Spice SQL REPL (run spice sql in another terminal), query the table:
SELECT * FROM orders_stream;You should see the new record:
+-----------+----------+--------+---------+
| id | customer | amount | status |
+-----------+----------+--------+---------+
| order-001 | Alice | 99.99 | pending |
+-----------+----------+--------+---------+Update the order status:
aws dynamodb put-item --table-name orders --item \
'{"id": {"S": "order-002"}, "customer": {"S": "Bob"}, "amount": {"N": "149.99"}, "status": {"S": "pending"}}' \
--region $AWS_REGIONQuery again in the SQL REPL:
SELECT * FROM orders_stream;The status should now be updated:
+-----------+----------+---------+---------+
| id | customer | amount | status |
+-----------+----------+---------+---------+
| order-001 | Alice | 99.99 | pending |
| order-002 | Bob | 199.99 | pending |
+-----------+----------+---------+---------+To delete the DynamoDB table:
aws dynamodb delete-table --table-name orders --region $AWS_REGIONFor more information, see the DynamoDB Streams documentation.