Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@aws-cdk/aws-applicationautoscaling
Advanced tools
The CDK Construct Library for 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.
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,
});
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.
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 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.
Application AutoScaling is used to configure autoscaling for all services other than scaling EC2 instances. For example, you will use this to scale ECS tasks, DynamoDB capacity, Spot Fleet sizes, Comprehend document classification endpoints, Lambda function provisioned concurrency and more.
As a CDK user, you will probably not have to interact with this library directly; instead, it will be used by other construct libraries to offer AutoScaling features for their own constructs.
This document will describe the general autoscaling features and concepts; your particular service may offer only a subset of these.
Resources can offer one or more attributes to autoscale, typically representing some capacity dimension of the underlying service. For example, a DynamoDB Table offers autoscaling of the read and write capacity of the table proper and its Global Secondary Indexes, an ECS Service offers autoscaling of its task count, an RDS Aurora cluster offers scaling of its replica count, and so on.
When you enable autoscaling for an attribute, you specify a minimum and a maximum value for the capacity. AutoScaling policies that respond to metrics will never go higher or lower than the indicated capacity (but scheduled scaling actions might, see below).
There are three ways to scale your capacity:
The general pattern of autoscaling will look like this:
const capacity = resource.autoScaleCapacity({
minCapacity: 5,
maxCapacity: 100
});
// Enable a type of metric scaling and/or schedule scaling
capacity.scaleOnMetric(...);
capacity.scaleToTrackMetric(...);
capacity.scaleOnSchedule(...);
This type of scaling scales in and out in deterministic steps that you configure, in response to metric values. For example, your scaling strategy to scale in response to CPU usage might look like this:
Scaling -1 (no change) +1 +3
│ │ │ │ │
├────────┼───────────────────────┼────────┼────────┤
│ │ │ │ │
CPU usage 0% 10% 50% 70% 100%
(Note that this is not necessarily a recommended scaling strategy, but it's a possible one. You will have to determine what thresholds are right for you).
You would configure it like this:
capacity.scaleOnMetric('ScaleToCPU', {
metric: service.metricCpuUtilization(),
scalingSteps: [
{ upper: 10, change: -1 },
{ lower: 50, change: +1 },
{ lower: 70, change: +3 },
],
// Change this to AdjustmentType.PercentChangeInCapacity to interpret the
// 'change' numbers before as percentages instead of capacity counts.
adjustmentType: autoscaling.AdjustmentType.CHANGE_IN_CAPACITY,
});
The AutoScaling construct library will create the required CloudWatch alarms and AutoScaling policies for you.
This type of scaling scales in and out in order to keep a metric (typically representing utilization) around a value you prefer. This type of scaling is typically heavily service-dependent in what metric you can use, and so different services will have different methods here to set up target tracking scaling.
The following example configures the read capacity of a DynamoDB table to be around 60% utilization:
const readCapacity = table.autoScaleReadCapacity({
minCapacity: 10,
maxCapacity: 1000
});
readCapacity.scaleOnUtilization({
targetUtilizationPercent: 60
});
This type of scaling is used to change capacities based on time. It works
by changing the minCapacity
and maxCapacity
of the attribute, and so
can be used for two purposes:
minCapacity
high or
the maxCapacity
low.minCapacity
and
maxCapacity
but changing their range over time).The following schedule expressions can be used:
at(yyyy-mm-ddThh:mm:ss)
-- scale at a particular moment in timerate(value unit)
-- scale every minute/hour/daycron(mm hh dd mm dow)
-- scale on arbitrary schedulesOf these, the cron expression is the most useful but also the most
complicated. A schedule is expressed as a cron expression. The Schedule
class has a cron
method to help build cron expressions.
The following example scales the fleet out in the morning, and lets natural scaling take over at night:
const capacity = resource.autoScaleCapacity({
minCapacity: 1,
maxCapacity: 50,
});
capacity.scaleOnSchedule('PrescaleInTheMorning', {
schedule: autoscaling.Schedule.cron({ hour: '8', minute: '0' }),
minCapacity: 20,
});
capacity.scaleOnSchedule('AllowDownscalingAtNight', {
schedule: autoscaling.Schedule.cron({ hour: '20', minute: '0' }),
minCapacity: 1
});
const handler = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
code: new lambda.InlineCode(`
import json, time
def handler(event, context):
time.sleep(1)
return {
'statusCode': 200,
'body': json.dumps('Hello CDK from Lambda!')
}`),
reservedConcurrentExecutions: 2,
});
const fnVer = handler.addVersion('CDKLambdaVersion', undefined, 'demo alias', 10);
new apigateway.LambdaRestApi(this, 'API', { handler: fnVer })
const target = new applicationautoscaling.ScalableTarget(this, 'ScalableTarget', {
serviceNamespace: applicationautoscaling.ServiceNamespace.LAMBDA,
maxCapacity: 100,
minCapacity: 10,
resourceId: `function:${handler.functionName}:${fnVer.version}`,
scalableDimension: 'lambda:function:ProvisionedConcurrency',
})
s
target.scaleToTrackMetric('PceTracking', {
targetValue: 0.9,
predefinedMetric: applicationautoscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
})
}
1.78.0 (2020-12-11)
HttpOrigin
and LoadBalancerOrigin
changed from SSLv3 to TLSv1.2.domainName
property under DomainName
has been
renamed to name
.dnsHostName
and awsCloudMap
of VirtualNodeProps
have been replaced with the property serviceDiscovery
metricFailed
uses Average
instead of Sum
by default (#11941) (3530e8c)FAQs
The CDK Construct Library for AWS::ApplicationAutoScaling
The npm package @aws-cdk/aws-applicationautoscaling receives a total of 105,494 weekly downloads. As such, @aws-cdk/aws-applicationautoscaling popularity was classified as popular.
We found that @aws-cdk/aws-applicationautoscaling demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.