บทนำ DynamoDB
ทำความเข้าใจประโยชน์ของบริการฐานข้อมูล NoSQL ที่มีการจัดการเต็มรูปแบบ รูปแบบความสอดคล้องของข้อมูล และองค์ประกอบหลัก
บทนำ DynamoDB เป็นบทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Welcome to DynamoDB!
Amazon DynamoDB is a fully managed NoSQL database service provided by AWS. It's designed for applications that require high performance at any scale, making it perfect for modern web, mobile, gaming, ad tech, and IoT applications.
As a NoSQL database, it offers flexibility with its schema-less design, meaning you don't need to define a rigid table structure upfront.
NoSQL vs. Traditional SQL
Unlike traditional relational (SQL) databases that use fixed schemas and tables with rows/columns, DynamoDB is a NoSQL (Not Only SQL) database. It stores data in a flexible, document-like format.
- Flexibility: No fixed schema, easy to evolve your data model.
- Scalability: Designed for massive scale with consistent performance.
- Performance: Delivers single-digit millisecond performance at any scale.
- Fully Managed: AWS handles patching, backups, and scaling, so you don't have to.
The Foundation: DynamoDB Tables
In DynamoDB, your data is organized into tables. A table is a collection of items, similar to how a table in a relational database is a collection of rows.
For example, you might have a Users table, a Products table, or an Orders table, each holding related data.
Data Units: Items & Attributes
Each table contains items. An item is a group of attributes that is uniquely identifiable among all other items. Think of an item as a row in a relational database.
An attribute is a fundamental data element, similar to a column. Unlike SQL, attributes can be added or removed from items dynamically, and different items in the same table can have different attributes.
Uniquely Identifying Items
Every item in a DynamoDB table must have a primary key, which uniquely identifies it. There are two types of primary keys:
- Partition Key: A simple primary key, like a user ID. DynamoDB uses its value as input to an internal hash function to determine where the item is stored.
- Composite Primary Key: Composed of a Partition Key and a Sort Key. This allows for more complex queries and ensures uniqueness within a partition.
Primary Key in Action
Let's say you have an Orders table. You could use OrderID as a simple Partition Key.
For a ForumPosts table, you might use ThreadID as the Partition Key and PostDateTime as the Sort Key. This allows you to find all posts in a thread, ordered by time.
{
"TableName": "ForumPosts",
"KeySchema": [
{"AttributeName": "ThreadID", "KeyType": "HASH"},
{"AttributeName": "PostDateTime", "KeyType": "RANGE"}
],
"AttributeDefinitions": [
{"AttributeName": "ThreadID", "AttributeType": "S"},
{"AttributeName": "PostDateTime", "AttributeType": "S"}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
}
}Eventual Consistency Explained
DynamoDB offers different consistency models. By default, reads are eventually consistent. This means that if you write data to DynamoDB and then immediately try to read it, you might not see the latest update.
The data will eventually become consistent, usually within milliseconds. This model is suitable for applications where immediate data consistency isn't critical, like social media feeds or user activity logs.
When You Need Strong Consistency
For situations where you need to be absolutely sure you're reading the latest data, DynamoDB offers strongly consistent reads. When you request a strongly consistent read, DynamoDB returns the most up-to-date data, reflecting all prior successful write operations.
This comes with a slight trade-off: strongly consistent reads might have higher latency and can consume more read capacity units.
Managing Capacity & Costs
DynamoDB offers two capacity modes to manage throughput and costs:
- On-Demand: DynamoDB automatically scales read/write capacity and you pay per request. Great for unpredictable workloads.
- Provisioned: You specify the number of reads and writes per second (Read/Write Capacity Units). Best for predictable workloads and often more cost-effective.
DynamoDB Consistency Check
You've learned about DynamoDB's core concepts and consistency models. Let's test your understanding.
DynamoDB: Key Takeaways
You've completed your introduction to Amazon DynamoDB! Here's a quick recap:
- DynamoDB is a fully managed, high-performance NoSQL database.
- It uses tables, composed of items and flexible attributes.
- Each item requires a primary key (Partition Key or Partition Key + Sort Key).
- It offers eventually consistent reads (default) and strongly consistent reads for different needs.
- You can choose between On-Demand and Provisioned capacity modes.
Next, we'll dive into DynamoDB Data Modeling!
คำถามที่พบบ่อย
บทเรียน “บทนำ DynamoDB” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “บทนำ DynamoDB” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “บทนำ DynamoDB”
ทำความเข้าใจประโยชน์ของบริการฐานข้อมูล NoSQL ที่มีการจัดการเต็มรูปแบบ รูปแบบความสอดคล้องของข้อมูล และองค์ประกอบหลัก คุณปฏิบัติ AWS for Backend Developers (EC2, S3, RDS, Lambda) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน AWS for Backend Developers (EC2, S3, RDS, Lambda) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “บทนำ DynamoDB” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) นี้ได้ไหม
ได้ บทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ