Soru

Zorluk: ZorData Store Operations with Amazon DynamoDB

A developer is designing a document management system where metadata is stored in an Amazon DynamoDB table with DocumentId as the partition key. The application must support two new requirements:
1. Retrieve all documents associated with a specific Department (e.g., 'HR') that were uploaded after a certain timestamp.
2. Retrieve a list of all documents that are flagged as containing malware (the IsMalicious attribute is set to true), which applies to less than 0.1% of all stored documents.

To optimize queries and minimize Read Capacity Units (RCUs) consumption, which two actions should the developer take? (Select TWO.)

  1. Create a Global Secondary Index (GSI) with Department as the partition key and UploadTimestamp as the sort key, and perform Query operations on this GSI.Cevap
  2. Create a sparse Global Secondary Index (GSI) with IsMalicious as the partition key, and perform Query operations on this GSI to retrieve the flagged documents.Cevap
  3. C
    Use a Scan operation on the base table with a FilterExpression containing Department and UploadTimestamp to retrieve the department documents.
  4. D
    Perform a Scan operation on the base table with a FilterExpression checking if IsMalicious is equal to true to retrieve the flagged documents.
  5. E
    Embed a long-lived IAM Access Key and Secret Access Key directly in the AWS SDK client configuration within the application code to speed up client initialization.

Cevap

Create a Global Secondary Index (GSI) with Department as the partition key and UploadTimestamp as the sort key, and create a sparse GSI with IsMalicious as the partition key, querying both indexes rather than scanning the base table.
The correct approach involves optimizing the two read access patterns using DynamoDB Query operations instead of Scan operations. For the first access pattern, creating a Global Secondary Index (GSI) with Department as the partition key and UploadTimestamp as the sort key allows the application to directly target the required items. For the second access pattern, a sparse GSI with IsMalicious as the partition key only indexes items that have this attribute set, which represents less than 0.1% of the database. Querying this sparse index is highly cost-effective and performs exceptionally fast because DynamoDB does not have to scan the non-matching items.

Adım Adım Çözüm

1
Analyze the access patterns and identify the primary query attributes.
The first access pattern queries on Department and filters/sorts on UploadTimestamp. The second access pattern queries a low-frequency boolean flag (IsMalicious = true).
Identifying the target query attributes helps determine whether to use the base table or secondary indexes.
2
Evaluate index design strategies to avoid Scan operations.
Creating a GSI with Department (partition key) and UploadTimestamp (sort key) enables Query operations for the first requirement. Since IsMalicious is present on less than 0.1% of items, creating a GSI with IsMalicious as the partition key will result in a sparse index containing only those items.
Queries on indexes are much more efficient and consume fewer RCUs than Scan operations on the base table.
3
Validate security credentials configuration according to AWS best practices.
Do not hardcode credentials in code. Ensure IAM roles and the default credential provider chain are used.
Hardcoding credentials creates security vulnerabilities and violates credential management guidelines.

Anahtar Kavram

Using Query operations on GSIs and sparse GSIs to optimize data retrieval and avoid Scan operations in DynamoDB.
Bu soruyu puanla