Skip to content

Return ConsumedCapacityUnits from DynamoDB Enhanced GetItem calls #4372

Closed
@psnilesh

Description

@psnilesh

Describe the feature

DynamoDB can return capacity units consumed by GetItem call if requested, but it is not supported by DynamoDbTable interface. Following are all the methods for loading data,

 interface DynamoDbTable<T> {
    ...
    T getItem(GetItemEnhancedRequest request);
    T getItem(Consumer<GetItemEnhancedRequest.Builder> requestConsumer);
    T getItem(Key key);
    T getItem(T keyItem);
}

However, this is already supported by Put, Update and Delete methods,

 interface DynamoDbTable<T> {
  ...
  PutItemEnhancedResponse<T> putItemWithResponse(PutItemEnhancedRequest<T> request)
  DeleteItemEnhancedResponse<T> deleteItemWithResponse(DeleteItemEnhancedRequest request)
  UpdateItemEnhancedResponse<T> updateItemWithResponse(UpdateItemEnhancedRequest<T> request)
}

// https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/model/UpdateItemEnhancedResponse.html
class UpdateItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
    private final ItemCollectionMetrics itemCollectionMetrics;
}

// https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/model/PutItemEnhancedResponse.html
class PutItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
    private final ItemCollectionMetrics itemCollectionMetrics;
}

// https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/model/DeleteItemEnhancedResponse.html
class DeleteItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
    private final ItemCollectionMetrics itemCollectionMetrics;
}


I propose we add ConsumedCapacity and ItemCollectionMetrics to for read operations as well in a backwards compatible manner.

Related to #1918

Use Case

We have a requirement where we need to accurately calculate capacity consumed by multiple DynamoDB requests made in succession. Having the metrics from DynamoDB would greatly simplify this work.

Proposed Solution

(Better names are welcome)

I propose we add and implement following new methods, similar to how Put, Update and Delete is implemented.

 interface DynamoDbTable<T> {
    // TODO: withResponse may not be the best suffix. It was alright for Put, Update and Delete since
    // their sibling methods are returning void. 
    GetItemEnhancedResponse<T> getItemWithResponse(T keyItem);
    GetItemEnhancedResponse<T> getItemWithResponse(Key key);
    ...
}

class GetItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
}

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Java SDK version used

2.x

JDK version used

Java8 or newer

Operating System and version

ALL

Metadata

Metadata

Assignees

No one assigned

    Labels

    dynamodb-enhancedfeature-requestA feature should be added or improved.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions