AWS Certified Developer - Associate
Databases
DynamoDB API
In this lesson, you'll learn about the DynamoDB API and how to perform essential CRUD operations—Create, Read, Update, and Delete—on a DynamoDB table. These operations form the backbone of most applications that integrate with DynamoDB.
CRUD Operations
Retrieve an Item (GetItem)
The GetItem API is used to fetch an item from the table by providing its partition key (and sort key when applicable). This operation returns the exact item that matches the provided key values.
Add, Update, and Delete Items
- PutItem: Use this API to add a new item or replace an entire item in your DynamoDB table.
- UpdateItem: This API helps you modify attributes of an existing item.
- DeleteItem: Employ this API to remove an item based on its key values.
Querying Data in DynamoDB
DynamoDB offers several methods to read data tailored to different use cases:
GetItem
- Retrieves a single item by its unique partition key (and sort key, if applicable).
Query
- Returns one or more items that share the same partition key, with the option to filter further using a sort key.
- Query operations are optimized using indexes, making them highly efficient.
- This method is particularly useful when working with Global Secondary Indexes (GSIs) and Local Secondary Indexes (LSIs).
Scan
- Scans the entire table and returns all items, regardless of their key values.
- Although comprehensive, scans are less efficient and more resource-intensive because every item is read before any filtering is applied.
Additional Table Operations
DynamoDB also supports table-level API actions that go beyond basic CRUD operations:
- CreateTable: Create a new table.
- DeleteTable: Remove an existing table.
- BatchWriteItem: Add or delete up to 25 items in a single API call.
- BatchGetItem: Retrieve up to 100 items from one or more tables concurrently.
Projection Expression
By default, read operations like GetItem, Query, or Scan return all attributes of an item. If only a subset of attributes is required, you can use a Projection Expression.
For example, if you have a user table and only need the user ID and email address, a projection expression allows you to retrieve just these attributes. This method minimizes data transfer and improves performance.
Note
Using projection expressions not only enhances performance but also reduces costs by ensuring that only necessary data is transmitted.
Summary
This lesson explored the key DynamoDB APIs for CRUD operations, data querying, and table management. Additionally, it discussed the use of projection expressions to optimize data retrieval. Understanding these features will enable you to build more efficient and scalable applications with DynamoDB.
For more details on DynamoDB and its applications, visit the AWS DynamoDB Documentation.
Watch Video
Watch video content