簡體   English   中英

如何使用JavaScript SDK設置DynamoDB表的按需容量

[英]How to set on-demand capacity for a DynamoDB table using JavaScript SDK

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

如何設置表的按需容量?

您將要按照AWS JavaScript SDK createTable docs中的說明設置BillingMode 將以下內容添加到您的參數中:

BillingMode: 'PAY_PER_REQUEST',

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM