Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS dynamodb create table with "on-demand" ProvisionedThroughput

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();
like image 678
SimpleJ Avatar asked May 13 '19 19:05

SimpleJ


People also ask

What is on-demand mode in DynamoDB?

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.

How many requests per second can DynamoDB handle?

DynamoDB can handle more than 10 trillion requests per day and can support peaks of more than 20 million requests per second.

How do I enable auto scaling in DynamoDB?

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.


1 Answers

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();
like image 61
Deiv Avatar answered Nov 14 '22 04:11

Deiv