Exam Guide: Developer - Associate
🏗️ Domain 1: Development with AWS Services
📘 Task 3: Use Data Stores In Application Development
DynamoDB dominates this task. The need to understand table design, key selection, indexing, consistency models, and how to write efficient queries is essential. As well as caching with ElastiCache and DAX. Plus specialized stores like OpenSearch.
📘 Concepts
DynamoDB Key Concepts
Primary Keys
Every table needs one. Two options:
Simple primary key: Partition key only (PK). Each item has a unique PK.
Composite primary key: Partition key (PK) + Sort key (SK). Multiple items can share a PK if they have different SKs.
Partition Key Selection
The partition key determines which physical partition stores your data. A good partition key has high cardinality which refers to many distinct values so that the data spreads evenly.
| Good Partition Keys | Bad Partition Keys |
|---|---|
| userId, orderId, sessionId | status ("active"/"inactive") |
| deviceId, transactionId | country (few values, uneven distribution) |
| email, accountId | date (hot partition for today) |
Consistency Models
| Model | Behaviour | Cost | Available On |
|---|---|---|---|
| Eventually Consistent | May return stale data (usually consistent within 1 second) | 1x read capacity | Base table + GSIs |
| Strongly Consistent | Always returns the most up-to-date data | 2x read capacity | Base table only (NOT GSIs) |
Query vs Scan
| Operation | How It Works | Cost | When to Use |
|---|---|---|---|
| Query | Finds items by partition key + optional sort key condition | Reads only matching items | Always prefer this |
| Scan | Reads every item in the table | Reads entire table | Analytics, one-time migrations only |
| GetItem | Fetches one item by its full primary key | Reads exactly one item | When you know the exact key |
FilterExpressiondoes NOT reduce the amount of data read. It only filters what's returned to you. You still pay for the full scan/query. To reduce reads, use better key design or GSIs.
Global Secondary Index (GSI) vs Local Secondary Index (LSI)
| Feature | GSI | LSI |
|---|---|---|
| Partition Key | Different from base table | Same as base table |
| Sort Key | Different from base table | Different from base table |
| When To Create | Anytime | At table creation only |
| Throughput | Has its own (separate from base table) | Shares with base table |
| Consistency | Eventually consistent only | Supports strongly consistent |
| Limit | 20 per table | 5 per table |
GSI Projection Types:
ALL: all attributes (most flexible, most storage cost)
KEYS_ONLY: only key attributes (cheapest)
INCLUDE: keys + specified attributes (balanced)
Caching Options
| Service | Use Case | Latency | Works With |
|---|---|---|---|
| DAX | DynamoDB read cache | Microseconds | DynamoDB only, eventually consistent only |
| ElastiCache Redis | General-purpose cache | Sub-millisecond | Any data source, complex data types, persistence |
| ElastiCache Memcached | Simple caching | Sub-millisecond | Any data source, multi-threaded, no persistence |
Specialized Data Stores
| Store | Use Case |
|---|---|
| DynamoDB | Key-value lookups, known access patterns, serverless |
| RDS/Aurora | Relational data, complex joins, ACID transactions |
| OpenSearch | Full-text search, log analytics, complex queries |
| S3 | Object storage, data lake, large files |
| ElastiCache | Session storage, leaderboards, real-time analytics |
Data Lifecycle
DynamoDB TTL
Automatically deletes expired items at no cost. Eventually consistent (up to 48 hours delay).
S3 Lifecycle Policies
Transition objects between storage classes (Standard → IA → Glacier) or expire them after a set time.
🏗️ Build A Product Catalog API
Now let's put these concepts into practice by builidng a Product Catalog API backed by DynamoDB:
- A DynamoDB table with a composite primary key and a Global Secondary Index (GSI)
- A Lambda function that performs queries, scans, and writes
- TTL configured for automatic data expiration
- DAX caching in front of DynamoDB
- A clear understanding of when to use query vs scan, GSI vs LSI, and strong vs eventual consistency
Prerequisites
to set a time a few minutes in the future for testing.
💡 TTL deletion is eventually consistent: items may persist for up to 48 hours after expiration. Don't rely on TTL for exact timing. Always filter out expired items in your queries as a safety measure.
Part VII
Caching with DAX
DAX (DynamoDB Accelerator) is an in-memory cache that sits in front of DynamoDB. It's a drop-in replacement. Same API, just change the client endpoint.
When to Use DAX
Scenario
Use DAX?
Read-heavy workload, same items queried repeatedly
Yes
Microsecond response times needed
Yes
Write-heavy workload
No (DAX is a read cache)
Need strongly consistent reads
No (DAX returns eventually consistent)
Diverse access patterns, rarely same item twice
No (low cache hit rate)
How DAX Works
CODEWithout DAX:
App → DynamoDB (single-digit millisecond reads)
With DAX:
App → DAX (microsecond reads if cached) → DynamoDB (on cache miss)
Console Walkthrough (Don't Create.Just Understand)
💸 DAX requires a VPC and costs money even when idle. We'll walk through the setup without creating it.
Step 01: Click ▼ DAX
Step 02: Click Create cluster
Cluster name:product-cache
Node type family:t-type family
Node type:dax.t3.small
Cluster size:3nodes (for high availability)
Click Next
Step 03: Configure networks
Network Type:IPv4
Subnet group:Create new
Subnet group name:MySubnetGroup
VPC ID:defaultVPC
Subnets:Select all
Security group:default ▼
Click View in EC2 console
Step 04: Allow port 8111 from your Lambda functions
✅Green banner: Inbound security group rules successfully modified on security group
Step 05: Configure Security
IAM Service role for DynamoDB access:Create new
IAM role name:DaxToDynamoDB
Click Next → Click Next → Click Create cluster
✅Green banner: Successfully created the cluster product-cache.
Step 06: In your Lambda code, you'd change one line:
CODE# Without DAX
dynamodb = boto3.resource('dynamodb')
# With DAX — same API, just different endpoint
import amazondax
dax_client = amazondax.AmazonDaxClient(
endpoints=['product-cache.abc123.dax-clusters.us-east-1.amazonaws.com:8111']
)
table = dax_client.Table('ProductCatalog')
# All your existing code works unchanged!
DAX is a drop-in replacement for DynamoDB reads. Same API, same code. Just change the client. 💡 But remember: DAX only supports eventually consistent reads and is for read-heavy workloads.
🏗️ What You Built | 📘Exam Concepts Recap
What You Did
Exam Concept
Designed a table around access patterns first
Access-pattern-driven DynamoDB design
Created a composite primary key (PK + SK)
Single-table design, sort key relationships
Added a Global Secondary Index with different keys
GSI for alternate access patterns
Used overloaded keys ( PRODUCT#,CATEGORY#,REVIEW#)
Single-table design pattern
Queried by partition key with begins_withon sort key
Efficient query operations
Ran a scan and compared CountvsScannedCount
Scan is expensive: it reads the entire table
Added a FilterExpressionto a scan
Filters run AFTER reading: don't save capacity
Used Decimal(str(price))instead offloat
DynamoDB type system: no float support
Toggled ConsistentRead=Trueonget_item
Strongly vs eventually consistent reads
Noted GSIs only support eventual consistency
GSI limitations
Enabled TTL on a ttlattribute
Automatic data lifecycle management
Walked through DAX setup
Read caching for DynamoDB, microsecond latency
⚠️ Clean Up Protocol
1. DynamoDB → Delete the
ProductCatalogtable
2. Lambda → DeleteProductCatalogAPI
3. IAM → Delete the Lambda execution role
4. CloudWatch → Delete the log groups
Key Takeaways
Partition key cardinality: high cardinality = even distribution = good performance
Query > Scan: always prefer query. Scan reads the entire table.
FilterExpression doesn't save reads: it filters after reading. Use key design or GSIs instead.
GSIs can be added anytime. LSIs must be created with the table
GSIs are eventually consistent only: no strongly consistent reads on GSIs
Use Decimal, not float for DynamoDB numbers in Python
TTL is free but eventually consistent (up to 48 hours delay)
DAX = DynamoDB read cache (microsecond reads). Same API as DynamoDB.- DAX doesn't support strongly consistent reads
Single-table design with overloaded keys is the recommended DynamoDB pattern
Additional Resources
🏗️
↗ Original-Artikel auf dev.to lesenVollständiger Original-ArtikelDen kompletten Beitrag mit allen Details direkt auf dev.to lesen.
SOCIAL SHARE CARD GENERATOR