【问题标题】:How to set on-demand capacity for a DynamoDB table using JavaScript SDK如何使用 JavaScript SDK 为 DynamoDB 表设置按需容量
【发布时间】:2019-01-25 02:23:27
【问题描述】:

Amazon DynamoDB 有两种读/写容量模式来处理对表的读取和写入: 一经请求 预配(默认,符合免费套餐条件)

这就是我创建预置表的方式

var AWS = require("aws-sdk");

AWS.config.update({
  region: "us-west-2",
  endpoint: "http://localhost:8000"
});

var dynamodb = new AWS.DynamoDB();

var params = {
    TableName : "Movies",
    KeySchema: [       
        { AttributeName: "year", KeyType: "HASH"},  //Partition key
        { AttributeName: "title", KeyType: "RANGE" }  //Sort key
    ],
    AttributeDefinitions: [       
        { AttributeName: "year", AttributeType: "N" },
        { AttributeName: "title", AttributeType: "S" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 10, 
        WriteCapacityUnits: 10
    }
};

dynamodb.createTable(params, function(err, data) {
    if (err) {
        console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
    }
});

如何设置表的按需容量?

【问题讨论】:

  • 所以,我刚刚意识到您询问的是按需容量,而不是定价。你的意思是像我想象的那样定价吗?如果您实际上是指容量,答案是您没有设置它,因此您可以摆脱容量参数。这种情况下的容量基本上是无限的。这就是按需计费模式的美妙之处。
  • 感谢您的回复)我认为您的回答是正确的。我现在无法检查。是的,我需要按需容量,我认为开启 PAY_PER_REQUEST 计费模式是一种解决方案,因为当您在控制台中开启按需容量时,您需要按请求付费

标签: node.js amazon-web-services amazon-dynamodb


【解决方案1】:

您需要按照 AWS JavaScript 开发工具包createTable docs 中的说明设置BillingMode。将以下内容添加到您的参数中:

BillingMode: 'PAY_PER_REQUEST',

【讨论】:

    猜你喜欢
    • 2023-02-02
    • 2019-05-08
    • 2018-06-21
    • 2022-01-25
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    相关资源
    最近更新 更多