ProvisionedThroughputExceededException after the update of node package from aws-sdk to @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb

2

Hello, following the imminent deactivation of the aws-sdk library, I have updated my project ( nodejs lambda ) by installing the new @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb packages to allow the same code to continue to be used with minimal update changes. The libraries worked as I expected, but after slightly more intensive use, a number of throughput problems were encountered. At first I thought this was normal, but then reading the monitoring logs, I noticed that the read or write capacity used to make the call was double that of the same call made with the previous aws-sdk library.

Under certain circumstances, it becomes so high that it does not allow new calls to be made for a long time unless the total capacity of the reference table is naturally increased. Trying again with the old library, the capacity returned to normal instead.

Is it possible to understand why this difference in capacity? Am I doing something wrong?

To avoid this, I am writing the modified part of the code for a little help:

  • aws-sdk

const AWS = require("aws-sdk");
const doc = require('dynamodb-doc');\

AWS.config.update({
region: 'eu-west-1'
});
const dynamo = new doc.DynamoDB(new AWS.DynamoDB());
....
dynamo.query(param, cb)

  • @aws-sdk

const { DynamoDB } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocument } = require("@aws-sdk/lib-dynamodb");
const clientDynamo = new DynamoDB({
region: 'eu-west-1'
});
const dynamo = DynamoDBDocument.from(clientDynamo);
....
dynamo.query(param).then(...)

asked a year ago613 views
2 Answers
1
Accepted Answer

There is no difference in capacity consumption between clients. Ensure that you set you are not setting your reads to be strongly consistent, as this would consume double the capacity and is aligned with your issue.

Read consistency is eventual consistent by default.

SDK V2

npm list
Nodetest@ /Users/lhnng/Documents/Nodetest
├── aws-sdk@2.1380.0
└── dynamodb-doc@1.0.0
{ TableName: 'test', CapacityUnits: 150.5 }

SDK V3

npm list
NodetestV3@ /Users/lhnng/Documents/NodetestV3
├── @aws-sdk/client-dynamodb@3.284.0
└── @aws-sdk/lib-dynamodb@3.272.0
{
  CapacityUnits: 150.5,
  GlobalSecondaryIndexes: undefined,
  LocalSecondaryIndexes: undefined,
  ReadCapacityUnits: undefined,
  Table: undefined,
  TableName: 'test',
  WriteCapacityUnits: undefined
}

Request:

client.query({
    "TableName": 'test',
    "KeyConditionExpression": `#pk = :val`,
    "ExpressionAttributeNames": {
        "#pk": "pk"
    },
    "ExpressionAttributeValues": {
        ":val": "sample_pk"
    },
    "ReturnConsumedCapacity": "TOTAL"
})
    .promise() // V2 has promise, V3 returns a promise by default
    .then(res => console.log(res['ConsumedCapacity']))
    .catch(err => console.log(err))

Conclusion

As I mentioned previously, there are no differences in consumed capacity depending on the client. I also ran using the CLI to assure you that there are no differences:

aws dynamodb query \
--table-name test \
--key-condition-expression "#pk = :pk" \
--expression-attribute-values '{":pk":{"S":"sample_pk"}}' \
--expression-attribute-names '{"#pk":"pk"}' \
--select COUNT \
--return-consumed-capacity TOTAL
{
    "Count": 26,
    "ScannedCount": 26,
    "ConsumedCapacity": {
        "TableName": "test",
        "CapacityUnits": 150.5
    }
}
profile pictureAWS
EXPERT
answered a year ago
  • Thank you very much for your reply, however as you can see from the configuration I have brought, I have not entered any changes. If there is a way to set the parameter to the default value, I would thank you if you could explain how. Or is there some reason why @aws-sdk keeps saying that I have reached ProvisionedThroughputExceededException preventing me from continuing whereas with aws-sdk it doesn't?

  • Can you provide me the version which you used in V2 and the version you now use in your upgraded V3. I will run some tests to ensure the SDK has not regressed.

  • Of course: aws-sdk: "2.1380.0" dynamodb-doc: "1.0.0" @aws-sdk/client-dynamodb: "3.284.0" @aws-sdk/lib-dynamodb: "3.272.0"

  • Thanks for that, updated my answer with my tests

  • I also tested for pagination scan, and the results are

    1. with aws-sdk 2, the results like
    { TableName: 'test', ScannedCount: 2969, CapacityUnits: 128.5 }
    { TableName: 'test', ScannedCount: 2969, CapacityUnits: 128.5 }
    { TableName: 'test', ScannedCount: 2969, CapacityUnits: 128.5 }
    { TableName: 'test', ScannedCount: 2969, CapacityUnits: 128.5 }
    { TableName: 'test', ScannedCount: 2969, CapacityUnits: 128.5 }
    

    And everything works fine, all results are scanned without error.

    1. With @aws-sdk v3 The result like
    { TableName: 'test', ScannedCount: 2969, CapacityUnits: 128.5 }
    { TableName: 'test', ScannedCount: 2940, CapacityUnits: 128.5 }
    ProvisionedThroughputExceededException
    

    So the scanned count and Consumed CapacityUnits are no difference, but aws-sdk v3 throws error.

-1

I have the exact same issue, I am using aws-sdk v2 and scan all data from dynamodb by while loop with LastEvaluatedKey, and everything works fine, after I upgrade to @aws-sdk/client-dynamodb, the ProvisionedThroughputExceededException is thrown, all configuration are exactly same, I am not setting ConsistentRead to true, I also tried paginateScan, the same error occurs.

Jia Li
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions