AWS — DynamoDB
What is DynamoDB?
Fully managed NoSQL database service.
Create table
aws dynamodb create-table \
--table-name Users \
--attribute-definitions \
AttributeName=id,AttributeType=N \
--key-schema AttributeName=id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
Put item
aws dynamodb put-item \
--table-name Users \
--item '{"id": {"N": "1"}, "name": {"S": "John"}, "email": {"S": "john@example.com"}}'
Get item
aws dynamodb get-item \
--table-name Users \
--key '{"id": {"N": "1"}}'
Query
aws dynamodb query \
--table-name Users \
--key-condition-expression "id = :id" \
--expression-attribute-values '{":id": {"N": "1"}}'
Scan
aws dynamodb scan --table-name Users
Update item
aws dynamodb update-item \
--table-name Users \
--key '{"id": {"N": "1"}}' \
--update-expression "SET email = :email" \
--expression-attribute-values '{":email": {"S": "new@example.com"}}'
Delete item
aws dynamodb delete-item \
--table-name Users \
--key '{"id": {"N": "1"}}'
Global Secondary Index
aws dynamodb update-table \
--table-name Users \
--attribute-definitions \
AttributeName=email,AttributeType=S \
--global-secondary-index-updates \
"[{\"Create\":{\"IndexName\":\"email-index\",\"KeySchema\":[{\"AttributeName\":\"email\",\"KeyType\":\"HASH\"}],\"Projection\":{\"ProjectionType\":\"ALL\"}}}]"
Best practices
- Design for uniform access
- Use sparse indexes
- Enable auto scaling
- Use DAX for caching
Mini Practice
- Create a table
- CRUD operations
- Query with indexes
- Enable auto scaling
Up Next
Continue with SQS - Message Queues.
Related Topics
Frequently Asked Questions about DynamoDB
What is DynamoDB in AWS?
DynamoDB is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn DynamoDB?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn DynamoDB.
Why is DynamoDB important in AWS?
DynamoDB is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.