awslabs / dynamodb-data-mapper-js

A schema-based data mapper for Amazon DynamoDB.
https://awslabs.github.io/dynamodb-data-mapper-js/
Apache License 2.0
817 stars 106 forks source link

Consumed Capacity Not Returning #178

Open ebeltran1981 opened 4 years ago

ebeltran1981 commented 4 years ago

Hello,

Using the native DynamoDB client I am able to get the consumed capacity of a Get, Put, Scan, Query, etc... but using the mapper I am not able to find how to pass the ReturnConsumedCapacity = "TOTAL" option.

Consider the following function:

async function scanGSI() {
  const scanParams: ScanParameters<User> = {
    valueConstructor: User,
    filter: {
      type: "Equals",
      subject: "vNo",
      object: "8004383"
    },
    indexName: vNumberGSI,
    // I am expecting something like this:
    returnConsumedCapacity: "TOTAL" // This doesn't work
  };

  const mapperScan = mapper.scan(scanParams);
  for await (const record of mapperScan) {}
  logger.debug(`consumed capacity: ${mapperScan.consumedCapacity}`); // <-- returns undefined
  logger.debug(`scanned count: ${mapperScan.count}`); // <-- this works
}

Is this functionality supported? if so, need help on how to implemented.

Thanks!

gricey432 commented 4 years ago

I ran into this same issue, managed to work around it by setting the DynamoDB Client's params to always inject ReturnConsumedCapacity.

export const dynamodbMapper = new DataMapper({
    client: new DynamoDB({region: 'ap-southeast-2', params: {ReturnConsumedCapacity: "TOTAL"}}),
    tableNamePrefix: 'dev_',
});

See aws sdk docs