Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Amazon DynamoDB for Developers | Storage, Databases and Caching
AWS Certified Developer - Associate

bookAmazon DynamoDB for Developers

Explore Amazon DynamoDB, AWS's serverless NoSQL database designed for speed and scalability. Ideal for high-traffic apps, IoT, or gaming, it handles millions of requests per second with low latency — all without infrastructure concerns.

Why Choose DynamoDB?

DynamoDB is a serverless NoSQL database, meaning:

  • No servers to provision, patch, or manage;
  • Automatic scaling based on your application's needs;
  • Pay only for what you use with flexible pricing models.

It's especially useful when you need to store:

  • Key-value pairs (like a dictionary/map);
  • JSON-like documents (flexible schemas);
  • Need to store low-latency write and read operations.

Core Concepts

Tables, Items, and Attributes

  • Data in DynamoDB is stored in tables;
  • Each table contains items, which are similar to rows in relational databases;
  • Each item is composed of attributes, which are like columns—but the structure can vary between items;
  • There's no fixed schema, making it flexible for evolving data models.

Keys

Every table requires at least a:

  • Partition key: determines how data is distributed across internal partitions;
  • Sort key (optional): enables multiple items to share the same partition key but be distinguished and sorted by this value.
Note
Note

Unlike traditional databases, DynamoDB does not support joins, foreign keys, or SQL queries. Data modeling should be driven by access patterns, not normalization.

Indexing and Queries

DynamoDB provides indexing options to optimize query flexibility:

Global Secondary Index (GSI)

  • Allows querying by different keys from the base table;
  • Ideal when you need multiple ways to access data (e.g., by username instead of user ID).

Local Secondary Index (LSI)

  • Uses the same partition key, but a different sort key;
  • Useful for filtering data within a single partition based on other attributes.

Advanced Features

Transactions

  • Enables atomic operations across multiple items and tables;
  • Ensures data consistency in financial, inventory, or user-related systems.

Time to Live (TTL)

  • Attach an expiry timestamp to records;
  • DynamoDB will automatically delete expired items — perfect for session tokens, temporary cache, or logs.

DynamoDB Streams

DynamoDB Streams captures every item-level change (insert, update, delete) in near real-time and stores them for 24 hours.

You can:

  • Trigger AWS Lambda functions in response;
  • Build event-driven workflows like sending notifications, syncing data, updating analytics dashboards, or even audit trails;
  • Avoid manual polling, reducing overhead.

Creating a Table from the AWS CLI

Let's walk through creating a table called orders using the AWS CLI:

aws dynamodb create-table \
  --table-name orders \
  --attribute-definitions \
    AttributeName=user_id,AttributeType=S \
    AttributeName=order_id,AttributeType=S \
  --key-schema \
    AttributeName=user_id,KeyType=HASH \
    AttributeName=order_id,KeyType=RANGE \
  --provisioned-throughput \
    ReadCapacityUnits=5 \
    WriteCapacityUnits=5
  • user_id: partition key;
  • order_id: sort key;
  • Provisioned Throughput: setting read and write capacity manually (more on this below).

Once created, verify it:

aws dynamodb describe-table --table-name orders

And finally, to clean up and avoid charges:

aws dynamodb delete-table --table-name orders

Capacity Modes

DynamoDB supports two capacity modes:

Provisioned Mode

  • You manually specify read and write units;
  • Suitable for predictable workloads;
  • Supports auto-scaling to adjust capacity based on usage.

On-Demand Mode

  • No upfront capacity planning;
  • Pay per request (read/write);
  • Ideal for spiky or unpredictable traffic.
Note
Note

For production, on-demand mode offers simplicity. If your workload is stable and predictable, provisioned mode with autoscaling can be more cost-effective.

Monitoring and Optimization

Use Amazon CloudWatch to:

  • Track performance metrics;
  • Identify throttling events, which signal your application is exceeding the provisioned throughput;
  • Optimize access patterns or scale up as needed.

Summary

Amazon DynamoDB is:

  • Fast: consistently low-latency reads and writes;
  • Scalable: handles millions of operations seamlessly;
  • Serverless: zero infrastructure to manage;
  • Feature-rich: with streams, TTL, indexes, and transactions.
Note
Tip

Design your schema based on how you query the data, not how it's structured. Think in terms of access patterns, not normalization.

1. Which of the following best describes Amazon DynamoDB?

2. What are the primary components of a DynamoDB table?

3. True or False: DynamoDB supports SQL queries and table joins.

4. What does a Global Secondary Index (GSI) allow you to do?

5. True or False: A Local Secondary Index (LSI) allows you to query using a different partition key.

6. Which feature allows you to automatically delete expired records in DynamoDB?

7. What is required at a minimum when defining a DynamoDB table?

8. Which DynamoDB capacity mode is ideal for unpredictable traffic patterns?

9. What can DynamoDB Streams be used for?

10. True or False: DynamoDB is optimized for schema-first design and data normalization.

question mark

Which of the following best describes Amazon DynamoDB?

Select the correct answer

question mark

What are the primary components of a DynamoDB table?

Select the correct answer

question mark

True or False: DynamoDB supports SQL queries and table joins.

Select the correct answer

question mark

What does a Global Secondary Index (GSI) allow you to do?

Select the correct answer

question mark

True or False: A Local Secondary Index (LSI) allows you to query using a different partition key.

Select the correct answer

question mark

Which feature allows you to automatically delete expired records in DynamoDB?

Select the correct answer

question mark

What is required at a minimum when defining a DynamoDB table?

Select the correct answer

question mark

Which DynamoDB capacity mode is ideal for unpredictable traffic patterns?

Select the correct answer

question mark

What can DynamoDB Streams be used for?

Select the correct answer

question mark

True or False: DynamoDB is optimized for schema-first design and data normalization.

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 1

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Awesome!

Completion rate improved to 6.25

bookAmazon DynamoDB for Developers

Sveip for å vise menyen

Explore Amazon DynamoDB, AWS's serverless NoSQL database designed for speed and scalability. Ideal for high-traffic apps, IoT, or gaming, it handles millions of requests per second with low latency — all without infrastructure concerns.

Why Choose DynamoDB?

DynamoDB is a serverless NoSQL database, meaning:

  • No servers to provision, patch, or manage;
  • Automatic scaling based on your application's needs;
  • Pay only for what you use with flexible pricing models.

It's especially useful when you need to store:

  • Key-value pairs (like a dictionary/map);
  • JSON-like documents (flexible schemas);
  • Need to store low-latency write and read operations.

Core Concepts

Tables, Items, and Attributes

  • Data in DynamoDB is stored in tables;
  • Each table contains items, which are similar to rows in relational databases;
  • Each item is composed of attributes, which are like columns—but the structure can vary between items;
  • There's no fixed schema, making it flexible for evolving data models.

Keys

Every table requires at least a:

  • Partition key: determines how data is distributed across internal partitions;
  • Sort key (optional): enables multiple items to share the same partition key but be distinguished and sorted by this value.
Note
Note

Unlike traditional databases, DynamoDB does not support joins, foreign keys, or SQL queries. Data modeling should be driven by access patterns, not normalization.

Indexing and Queries

DynamoDB provides indexing options to optimize query flexibility:

Global Secondary Index (GSI)

  • Allows querying by different keys from the base table;
  • Ideal when you need multiple ways to access data (e.g., by username instead of user ID).

Local Secondary Index (LSI)

  • Uses the same partition key, but a different sort key;
  • Useful for filtering data within a single partition based on other attributes.

Advanced Features

Transactions

  • Enables atomic operations across multiple items and tables;
  • Ensures data consistency in financial, inventory, or user-related systems.

Time to Live (TTL)

  • Attach an expiry timestamp to records;
  • DynamoDB will automatically delete expired items — perfect for session tokens, temporary cache, or logs.

DynamoDB Streams

DynamoDB Streams captures every item-level change (insert, update, delete) in near real-time and stores them for 24 hours.

You can:

  • Trigger AWS Lambda functions in response;
  • Build event-driven workflows like sending notifications, syncing data, updating analytics dashboards, or even audit trails;
  • Avoid manual polling, reducing overhead.

Creating a Table from the AWS CLI

Let's walk through creating a table called orders using the AWS CLI:

aws dynamodb create-table \
  --table-name orders \
  --attribute-definitions \
    AttributeName=user_id,AttributeType=S \
    AttributeName=order_id,AttributeType=S \
  --key-schema \
    AttributeName=user_id,KeyType=HASH \
    AttributeName=order_id,KeyType=RANGE \
  --provisioned-throughput \
    ReadCapacityUnits=5 \
    WriteCapacityUnits=5
  • user_id: partition key;
  • order_id: sort key;
  • Provisioned Throughput: setting read and write capacity manually (more on this below).

Once created, verify it:

aws dynamodb describe-table --table-name orders

And finally, to clean up and avoid charges:

aws dynamodb delete-table --table-name orders

Capacity Modes

DynamoDB supports two capacity modes:

Provisioned Mode

  • You manually specify read and write units;
  • Suitable for predictable workloads;
  • Supports auto-scaling to adjust capacity based on usage.

On-Demand Mode

  • No upfront capacity planning;
  • Pay per request (read/write);
  • Ideal for spiky or unpredictable traffic.
Note
Note

For production, on-demand mode offers simplicity. If your workload is stable and predictable, provisioned mode with autoscaling can be more cost-effective.

Monitoring and Optimization

Use Amazon CloudWatch to:

  • Track performance metrics;
  • Identify throttling events, which signal your application is exceeding the provisioned throughput;
  • Optimize access patterns or scale up as needed.

Summary

Amazon DynamoDB is:

  • Fast: consistently low-latency reads and writes;
  • Scalable: handles millions of operations seamlessly;
  • Serverless: zero infrastructure to manage;
  • Feature-rich: with streams, TTL, indexes, and transactions.
Note
Tip

Design your schema based on how you query the data, not how it's structured. Think in terms of access patterns, not normalization.

1. Which of the following best describes Amazon DynamoDB?

2. What are the primary components of a DynamoDB table?

3. True or False: DynamoDB supports SQL queries and table joins.

4. What does a Global Secondary Index (GSI) allow you to do?

5. True or False: A Local Secondary Index (LSI) allows you to query using a different partition key.

6. Which feature allows you to automatically delete expired records in DynamoDB?

7. What is required at a minimum when defining a DynamoDB table?

8. Which DynamoDB capacity mode is ideal for unpredictable traffic patterns?

9. What can DynamoDB Streams be used for?

10. True or False: DynamoDB is optimized for schema-first design and data normalization.

question mark

Which of the following best describes Amazon DynamoDB?

Select the correct answer

question mark

What are the primary components of a DynamoDB table?

Select the correct answer

question mark

True or False: DynamoDB supports SQL queries and table joins.

Select the correct answer

question mark

What does a Global Secondary Index (GSI) allow you to do?

Select the correct answer

question mark

True or False: A Local Secondary Index (LSI) allows you to query using a different partition key.

Select the correct answer

question mark

Which feature allows you to automatically delete expired records in DynamoDB?

Select the correct answer

question mark

What is required at a minimum when defining a DynamoDB table?

Select the correct answer

question mark

Which DynamoDB capacity mode is ideal for unpredictable traffic patterns?

Select the correct answer

question mark

What can DynamoDB Streams be used for?

Select the correct answer

question mark

True or False: DynamoDB is optimized for schema-first design and data normalization.

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 1
some-alt