如何使用Node SDK创建DynamoDB表,并将“按需”指定为ProvisionedThroughput
?当我忽略ProvisionedThroughput
选项时,会出现此错误:
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)
这是我的代码,试图创建表:
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();
答案 0 :(得分:3)
您必须设置BillingMode: PAY_PER_REQUEST
用于按需吞吐量。否则默认情况下将其设置为PROVISIONED
(documentation)。
您的代码应如下所示:
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();