How can I create a DynamoDB table using the Node SDK and specify "on-demand" as the ProvisionedThroughput
? I get this error when I leave out the ProvisionedThroughput
option:
ValidationException: One or more parameter values were invalid: ReadCapacityUnits and WriteCapacityUnits must both be specified when BillingMode is PROVISIONED
at Request.extractError (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/protocol/json.js:51:27)
at Request.callListeners (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/james/projects/ears/server/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
at Request.emit (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/james/projects/ears/server/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/james/projects/ears/server/node_modules/aws-sdk/lib/request.js:38:9)
Here is my code that attempts to create the table:
await dynamodb
.createTable({
TableName: `${studyName}StudyCodeDB`,
AttributeDefinitions: [
{
AttributeName: 'studyCode',
AttributeType: 'S',
},
{
AttributeName: 'studyCodeCreationDate',
AttributeType: 'N',
},
],
KeySchema: [
{
AttributeName: 'studyCode',
KeyType: 'HASH',
},
{
AttributeName: 'studyCodeCreationDate',
KeyType: 'RANGE',
},
],
})
.promise();
On-demand mode. Amazon DynamoDB on-demand is a flexible billing option capable of serving thousands of requests per second without capacity planning. DynamoDB on-demand offers pay-per-request pricing for read and write requests so that you pay only for what you use.
DynamoDB can handle more than 10 trillion requests per day and can support peaks of more than 20 million requests per second.
Select Customize settings. In the Read/write capacity settings section, select Provisioned capacity mode and set Auto scaling to On for Read capacity, Write capacity, or both.
You have to set BillingMode: PAY_PER_REQUEST
which is for on-demand throughput. Otherwise by default it's set to PROVISIONED
(documentation).
Your code should look like this:
await dynamodb
.createTable({
TableName: `${studyName}StudyCodeDB`,
BillingMode: 'PAY_PER_REQUEST',
AttributeDefinitions: [
{
AttributeName: 'studyCode',
AttributeType: 'S',
},
{
AttributeName: 'studyCodeCreationDate',
AttributeType: 'N',
},
],
KeySchema: [
{
AttributeName: 'studyCode',
KeyType: 'HASH',
},
{
AttributeName: 'studyCodeCreationDate',
KeyType: 'RANGE',
},
],
})
.promise();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With