What is @aws-cdk/aws-applicationautoscaling?
@aws-cdk/aws-applicationautoscaling is an AWS CDK library that allows you to configure application auto-scaling for various AWS resources. It provides constructs for defining scaling policies and targets, enabling you to automatically adjust capacity based on demand.
What are @aws-cdk/aws-applicationautoscaling's main functionalities?
Auto-scaling for DynamoDB
This feature allows you to set up auto-scaling for a DynamoDB table. The code sample demonstrates how to create a DynamoDB table and configure auto-scaling for its read capacity based on utilization.
const app = new cdk.App();
const stack = new cdk.Stack(app, 'AutoScalingStack');
const table = new dynamodb.Table(stack, 'MyTable', {
partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PROVISIONED,
});
const readScaling = table.autoScaleReadCapacity({
minCapacity: 1,
maxCapacity: 10,
});
readScaling.scaleOnUtilization({
targetUtilizationPercent: 75,
});
Auto-scaling for ECS Services
This feature allows you to set up auto-scaling for ECS services. The code sample demonstrates how to create an ECS Fargate service and configure auto-scaling based on CPU utilization.
const app = new cdk.App();
const stack = new cdk.Stack(app, 'AutoScalingStack');
const cluster = new ecs.Cluster(stack, 'Cluster', {
vpc,
});
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef');
const container = taskDefinition.addContainer('WebContainer', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
memoryLimitMiB: 512,
});
const service = new ecs.FargateService(stack, 'Service', {
cluster,
taskDefinition,
});
const scaling = service.autoScaleTaskCount({
minCapacity: 1,
maxCapacity: 10,
});
scaling.scaleOnCpuUtilization('CpuScaling', {
targetUtilizationPercent: 50,
});
Auto-scaling for Lambda Functions
This feature allows you to set up auto-scaling for Lambda functions. The code sample demonstrates how to create a Lambda function and configure auto-scaling based on utilization.
const app = new cdk.App();
const stack = new cdk.Stack(app, 'AutoScalingStack');
const fn = new lambda.Function(stack, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda'),
});
const alias = new lambda.Alias(stack, 'Alias', {
aliasName: 'prod',
version: fn.currentVersion,
});
const scaling = alias.addAutoScaling({
minCapacity: 1,
maxCapacity: 10,
});
scaling.scaleOnUtilization({
utilizationTarget: 0.75,
});
Other packages similar to @aws-cdk/aws-applicationautoscaling
aws-sdk
The aws-sdk package provides a comprehensive set of tools for interacting with AWS services, including auto-scaling. However, it requires more manual setup and configuration compared to the higher-level abstractions provided by @aws-cdk/aws-applicationautoscaling.
serverless
The serverless framework allows you to deploy and manage serverless applications on AWS and other cloud providers. It includes support for auto-scaling Lambda functions and other resources, but it is more focused on serverless architectures compared to the broader scope of @aws-cdk/aws-applicationautoscaling.
terraform
Terraform is an infrastructure as code tool that allows you to define and provision infrastructure using a declarative configuration language. It supports auto-scaling for various AWS resources, but it uses a different approach and syntax compared to the AWS CDK.