I am using AWS SDK for nodejs and creating a dynamodb table from the code. It all works fine but i need auto scaling to be enabled for provisioned read and write capacity. This is the code i am trying
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));
}
});
This creates a table with read and write capacity as 5 but with auto scaling disabled. I have seen a java sample where auto scaling is being handled from code but nothing for java script. Any suggestions on how to enable auto scaling from NodeJS will be very helpful . Thanks
To configure auto scaling in DynamoDB, you set the minimum and maximum levels of read and write capacity in addition to the target utilization percentage. Auto scaling uses Amazon CloudWatch to monitor a table’s read and write capacity metrics. To do so, it creates CloudWatch alarms that track consumed capacity.
DynamoDB auto scaling can increase read capacity or write capacity as often as necessary, in accordance with your auto scaling policy. All DynamoDB quotas remain in effect, as described in Service, Account, and Table Quotas in Amazon DynamoDB .
Provisioned with Auto-Scaling takes in a few option for both read capacity and write capacity in order to optimize your table: Target utilization - This is a percentage that DynamoDB will aim for your consumed table capacity to be this % of your total table capacity.
Probably the biggest limitation of On-Demand Scaling is the fact that you can only go from Provisioned Capacity to On-Demand Scaling once per day. This is a one direction limit, so theoretically you can go from On-Demand Scaling to Provisioned Capacity as many times as you'd like. Additionally, DynamoDB throughput default quotas still apply.
You can enable the auto-scaling through a separate ApplicationAutoScaling call.
Here a Lambda code sample of how to enable auto-scaling for write units:
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');
});
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With