javascript - AWS dynamodb create table with "on-demand" ProvisionedThroughput - Stack Overflow

How can I create a DynamoDB table using the Node SDK and specify "on-demand" as the Provision

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();

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();
Share asked May 13, 2019 at 19:41 SimpleJSimpleJ 14.8k13 gold badges61 silver badges96 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

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();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743684137a4489863.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信