Monitor Consumed Capacity in DynamoDB for Query Performance

How to Monitor Consumed Capacity in DynamoDB for Query Performance

Prev Question Next Question

Question

You are developing an application that is working with a DynamoDB table.

During the development phase, you want to know how much of the Consumed capacity is being used for the queries being fired.

How can this be achieved?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - C.

The AWS Documentation mentions the following.

By default, a Query operation does not return any data on how much read capacity it consumes.

However, you can specify the ReturnConsumedCapacity parameter in a Query request to obtain this information.

The following are the valid settings for ReturnConsumedCapacity.

NONE-no consumed capacity data is returned.

(This is the default).

TOTAL-the response includes the aggregate number of read capacity units consumed.

INDEXES-the response shows the aggregate number of read capacity units consumed, together with the consumed capacity for each table and index that was accessed.

Because of what the AWS Documentation mentions, all other options are invalid.

For more information on the Query operation, please refer to the below URL-

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html

The correct answer is B. Ensure to set the ReturnConsumedCapacity in the query request to TRUE.

When working with DynamoDB tables, every operation consumes some amount of capacity, which is measured in Capacity Units (CU). Capacity Units are calculated based on the size of the item being read/written, and the consistency level required. The capacity consumed can be measured in three ways:

  1. None: The capacity consumed is not returned as part of the response.
  2. Total: The total capacity consumed is returned as part of the response.
  3. Indexes: The capacity consumed by the global secondary indexes (if any) is returned as part of the response.

To get the consumed capacity for a query, you need to set the ReturnConsumedCapacity parameter to TRUE. This will return the consumed capacity for the query in the response. For example:

javascript
var params = { TableName: 'my-table', KeyConditionExpression: 'partitionKey = :pk', ExpressionAttributeValues: { ':pk': 'my-partition-key' }, ReturnConsumedCapacity: 'TOTAL' }; docClient.query(params, function(err, data) { if (err) { console.log('Error: ', err); } else { console.log('Consumed Capacity: ', data.ConsumedCapacity); } });

In the above example, we are querying the 'my-table' table for items with partition key 'my-partition-key', and setting the ReturnConsumedCapacity parameter to 'TOTAL'. This will return the total consumed capacity for the query in the 'ConsumedCapacity' field of the response.

Option A is incorrect because the queries by default do not return consumed capacity as part of the result.

Option C is incorrect because 'TOTAL' is the correct value to use for the ReturnConsumedCapacity parameter.

Option D is incorrect because the Scan operation scans the entire table and consumes a lot of capacity. It should only be used when necessary, as it can be very expensive.