如何从Java脚本为DynamoDB中的预置读取容量启用Auto Scaling

我正在使用AWS SDK for nodejs并从代码创build一个dynamodb表。 这一切工作正常,但我需要自动缩放来启用预置的读取和写入容量。 这是我正在尝试的代码

var params = { TableName : "MyTable", KeySchema: [ { AttributeName: "Name", KeyType: "HASH"}, //Partition key { AttributeName: "time", KeyType: "RANGE" } //Sort key ], AttributeDefinitions: [ { AttributeName: "Name", AttributeType: "S" }, { AttributeName: "time", AttributeType: "N" } ], ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } ] }; 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)); } }); 

这创build了一个读写容量为5的表,但禁用了自动缩放。 我看到一个Java示例,其中自动缩放正在从代码处理,但没有任何Java脚本。 关于如何从NodeJS启用自动扩展的任何build议将非常有帮助。 谢谢

您可以通过单独的ApplicationAutoScaling调用来启用自动缩放。

这里有一个关于如何为写单元启用自动缩放的Lambda代码示例:

 const AWS = require("aws-sdk"); var applicationautoscaling = new AWS.ApplicationAutoScaling({ apiVersion: '2016-02-06' }); exports.handler = (event, context, callback) => { var params = { MaxCapacity: 10, MinCapacity: 2, ResourceId: "table/MyTable", RoleARN: "arn:aws:iam::111111111:role/lambda_s3_exec_role", ScalableDimension: "dynamodb:table:WriteCapacityUnits", ServiceNamespace: "dynamodb" }; applicationautoscaling.registerScalableTarget(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.log(data); // successful response callback(null, 'write capacity adjusted'); }); };