A developer is designing an Amazon DynamoDB table named `UserActivities` to track user actions in a web application. The table's primary key is configured with `UserID` as the partition key and `ActivityTimestamp` as the sort key.
The application needs to support the following operations:
1. Retrieve all activities for a specific `UserID` that occurred within a particular date range, sorted by timestamp.
2. Retrieve all activities of a specific `ActivityType` (such as 'login' or 'purchase') across all users, sorted by the timestamp of the activity.
The developer wants to implement this with optimal performance and minimal read capacity consumption.
Which two actions should the developer take to meet these requirements? (Select TWO.)
- Query the base table directly using the UserID partition key and a key condition expression on the ActivityTimestamp sort key.Cevap
- Create a Global Secondary Index (GSI) with ActivityType as the partition key and ActivityTimestamp as the sort key.Cevap
- CCreate a Local Secondary Index (LSI) with ActivityType as the partition key and ActivityTimestamp as the sort key.
- DPerform a Scan operation on the base table using a FilterExpression on the ActivityType attribute to retrieve activities across all users.
- EInitialize the DynamoDB client in the application by hardcoding the AWS Access Key ID and Secret Access Key of an IAM user with full permissions to the table to ensure fast authentication.
Cevap
Query the base table using the partition key and sort key for the first pattern, and create a Global Secondary Index (GSI) with the activity type as the partition key and timestamp as the sort key for the second pattern.
Querying the base table directly with a key condition expression is the most efficient way to retrieve sorted data within a single partition (UserID). Creating a Global Secondary Index (GSI) with ActivityType as the partition key and ActivityTimestamp as the sort key enables querying across all partitions while maintaining the required timestamp sort order.
Adım Adım Çözüm
Anahtar Kavram
Selecting between base table queries, Local Secondary Indexes (LSIs), and Global Secondary Indexes (GSIs) based on access patterns.
Tahmini Süre:2m 0s