AWS Auto Scaling Construct Library
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.
AutoScaling basics
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:
- In response to a metric (also known as step scaling); for example, you might want to scale out if the CPU usage across your cluster starts to rise, and scale in when it drops again.
- By trying to keep a certain metric around a given value (also known as target tracking scaling); you might want to automatically scale out an in to keep your CPU usage around 50%.
- On a schedule; you might want to organize your scaling around traffic flows you expect, by scaling out in the morning and scaling in in the evening.
The general pattern of autoscaling will look like this:
declare const resource: SomeScalableResource;
const capacity = resource.autoScaleCapacity({
minCapacity: 5,
maxCapacity: 100
});
// Then call a method to enable metric scaling and/or schedule scaling
// (explained below):
//
// capacity.scaleOnMetric(...);
// capacity.scaleToTrackMetric(...);
// capacity.scaleOnSchedule(...);
# resource: SomeScalableResource
capacity = resource.auto_scale_capacity(
min_capacity=5,
max_capacity=100
)
SomeScalableResource resource;
ScalableAttribute capacity = resource.autoScaleCapacity(new Caps()
.minCapacity(5)
.maxCapacity(100)
);
SomeScalableResource resource;
var capacity = resource.AutoScaleCapacity(new Caps {
MinCapacity = 5,
MaxCapacity = 100
});
var resource someScalableResource
capacity := resource.autoScaleCapacity(&caps{
minCapacity: jsii.Number(5),
maxCapacity: jsii.Number(100),
})
Step Scaling
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:
declare const capacity: ScalableAttribute;
declare const cpuUtilization: cloudwatch.Metric;
capacity.scaleOnMetric('ScaleToCPU', {
metric: cpuUtilization,
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: appscaling.AdjustmentType.CHANGE_IN_CAPACITY,
});
# capacity: ScalableAttribute
# cpu_utilization: cloudwatch.Metric
capacity.scale_on_metric("ScaleToCPU",
metric=cpu_utilization,
scaling_steps=[appscaling.ScalingInterval(upper=10, change=-1), appscaling.ScalingInterval(lower=50, change=+1), appscaling.ScalingInterval(lower=70, change=+3)
],
# Change this to AdjustmentType.PercentChangeInCapacity to interpret the
# 'change' numbers before as percentages instead of capacity counts.
adjustment_type=appscaling.AdjustmentType.CHANGE_IN_CAPACITY
)
ScalableAttribute capacity;
Metric cpuUtilization;
capacity.scaleOnMetric("ScaleToCPU", BasicStepScalingPolicyProps.builder()
.metric(cpuUtilization)
.scalingSteps(List.of(ScalingInterval.builder().upper(10).change(-1).build(), ScalingInterval.builder().lower(50).change(+1).build(), ScalingInterval.builder().lower(70).change(+3).build()))
// Change this to AdjustmentType.PercentChangeInCapacity to interpret the
// 'change' numbers before as percentages instead of capacity counts.
.adjustmentType(AdjustmentType.CHANGE_IN_CAPACITY)
.build());
ScalableAttribute capacity;
Metric cpuUtilization;
capacity.ScaleOnMetric("ScaleToCPU", new BasicStepScalingPolicyProps {
Metric = cpuUtilization,
ScalingSteps = new [] { new ScalingInterval { Upper = 10, Change = -1 }, new ScalingInterval { Lower = 50, Change = +1 }, new ScalingInterval { Lower = 70, Change = +3 } },
// Change this to AdjustmentType.PercentChangeInCapacity to interpret the
// 'change' numbers before as percentages instead of capacity counts.
AdjustmentType = AdjustmentType.CHANGE_IN_CAPACITY
});
var capacity scalableAttribute
var cpuUtilization Metric
capacity.scaleOnMetric(jsii.String("ScaleToCPU"), &BasicStepScalingPolicyProps{
Metric: cpuUtilization,
ScalingSteps: []ScalingInterval{
&ScalingInterval{
Upper: jsii.Number(10),
Change: -jsii.Number(1),
},
&ScalingInterval{
Lower: jsii.Number(50),
Change: +jsii.Number(1),
},
&ScalingInterval{
Lower: jsii.Number(70),
Change: +jsii.Number(3),
},
},
// Change this to AdjustmentType.PercentChangeInCapacity to interpret the
// 'change' numbers before as percentages instead of capacity counts.
AdjustmentType: appscaling.AdjustmentType_CHANGE_IN_CAPACITY,
})
The AutoScaling construct library will create the required CloudWatch alarms and AutoScaling policies for you.
Scaling based on multiple datapoints
The Step Scaling configuration above will initiate a scaling event when a single datapoint of the scaling metric is breaching a scaling step breakpoint. In cases where you might want to initiate scaling actions on a larger number of datapoints (ie in order to smooth out randomness in the metric data), you can use the optional evaluationPeriods and datapointsToAlarm properties:
declare const capacity: ScalableAttribute;
declare const cpuUtilization: cloudwatch.Metric;
capacity.scaleOnMetric('ScaleToCPUWithMultipleDatapoints', {
metric: cpuUtilization,
scalingSteps: [
{ upper: 10, change: -1 },
{ lower: 50, change: +1 },
{ lower: 70, change: +3 },
],
// if the cpuUtilization metric has a period of 1 minute, then data points
// in the last 10 minutes will be evaluated
evaluationPeriods: 10,
// Only trigger a scaling action when 6 datapoints out of the last 10 are
// breaching. If this is left unspecified, then ALL datapoints in the
// evaluation period must be breaching to trigger a scaling action
datapointsToAlarm: 6
});
# capacity: ScalableAttribute
# cpu_utilization: cloudwatch.Metric
capacity.scale_on_metric("ScaleToCPUWithMultipleDatapoints",
metric=cpu_utilization,
scaling_steps=[appscaling.ScalingInterval(upper=10, change=-1), appscaling.ScalingInterval(lower=50, change=+1), appscaling.ScalingInterval(lower=70, change=+3)
],
# if the cpuUtilization metric has a period of 1 minute, then data points
# in the last 10 minutes will be evaluated
evaluation_periods=10,
# Only trigger a scaling action when 6 datapoints out of the last 10 are
# breaching. If this is left unspecified, then ALL datapoints in the
# evaluation period must be breaching to trigger a scaling action
datapoints_to_alarm=6
)
ScalableAttribute capacity;
Metric cpuUtilization;
capacity.scaleOnMetric("ScaleToCPUWithMultipleDatapoints", BasicStepScalingPolicyProps.builder()
.metric(cpuUtilization)
.scalingSteps(List.of(ScalingInterval.builder().upper(10).change(-1).build(), ScalingInterval.builder().lower(50).change(+1).build(), ScalingInterval.builder().lower(70).change(+3).build()))
// if the cpuUtilization metric has a period of 1 minute, then data points
// in the last 10 minutes will be evaluated
.evaluationPeriods(10)
// Only trigger a scaling action when 6 datapoints out of the last 10 are
// breaching. If this is left unspecified, then ALL datapoints in the
// evaluation period must be breaching to trigger a scaling action
.datapointsToAlarm(6)
.build());
ScalableAttribute capacity;
Metric cpuUtilization;
capacity.ScaleOnMetric("ScaleToCPUWithMultipleDatapoints", new BasicStepScalingPolicyProps {
Metric = cpuUtilization,
ScalingSteps = new [] { new ScalingInterval { Upper = 10, Change = -1 }, new ScalingInterval { Lower = 50, Change = +1 }, new ScalingInterval { Lower = 70, Change = +3 } },
// if the cpuUtilization metric has a period of 1 minute, then data points
// in the last 10 minutes will be evaluated
EvaluationPeriods = 10,
// Only trigger a scaling action when 6 datapoints out of the last 10 are
// breaching. If this is left unspecified, then ALL datapoints in the
// evaluation period must be breaching to trigger a scaling action
DatapointsToAlarm = 6
});
var capacity scalableAttribute
var cpuUtilization Metric
capacity.scaleOnMetric(jsii.String("ScaleToCPUWithMultipleDatapoints"), &BasicStepScalingPolicyProps{
Metric: cpuUtilization,
ScalingSteps: []ScalingInterval{
&ScalingInterval{
Upper: jsii.Number(10),
Change: -jsii.Number(1),
},
&ScalingInterval{
Lower: jsii.Number(50),
Change: +jsii.Number(1),
},
&ScalingInterval{
Lower: jsii.Number(70),
Change: +jsii.Number(3),
},
},
// if the cpuUtilization metric has a period of 1 minute, then data points
// in the last 10 minutes will be evaluated
EvaluationPeriods: jsii.Number(10),
// Only trigger a scaling action when 6 datapoints out of the last 10 are
// breaching. If this is left unspecified, then ALL datapoints in the
// evaluation period must be breaching to trigger a scaling action
DatapointsToAlarm: jsii.Number(6),
})
Target Tracking Scaling
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:
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
declare const table: dynamodb.Table;
const readCapacity = table.autoScaleReadCapacity({
minCapacity: 10,
maxCapacity: 1000
});
readCapacity.scaleOnUtilization({
targetUtilizationPercent: 60
});
import aws_cdk.aws_dynamodb as dynamodb
# table: dynamodb.Table
read_capacity = table.auto_scale_read_capacity(
min_capacity=10,
max_capacity=1000
)
read_capacity.scale_on_utilization(
target_utilization_percent=60
)
import software.amazon.awscdk.services.dynamodb.*;
Table table;
IScalableTableAttribute readCapacity = table.autoScaleReadCapacity(EnableScalingProps.builder()
.minCapacity(10)
.maxCapacity(1000)
.build());
readCapacity.scaleOnUtilization(UtilizationScalingProps.builder()
.targetUtilizationPercent(60)
.build());
using Amazon.CDK.AWS.DynamoDB;
Table table;
var readCapacity = table.AutoScaleReadCapacity(new EnableScalingProps {
MinCapacity = 10,
MaxCapacity = 1000
});
readCapacity.ScaleOnUtilization(new UtilizationScalingProps {
TargetUtilizationPercent = 60
});
import dynamodb "github.com/aws/aws-cdk-go/awscdk"
var table Table
readCapacity := table.AutoScaleReadCapacity(&EnableScalingProps{
MinCapacity: jsii.Number(10),
MaxCapacity: jsii.Number(1000),
})
readCapacity.ScaleOnUtilization(&UtilizationScalingProps{
TargetUtilizationPercent: jsii.Number(60),
})
Scheduled Scaling
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:
- Scale in and out on a schedule by setting the
minCapacityhigh or themaxCapacitylow. - Still allow the regular scaling actions to do their job, but restrict the range they can scale over (by setting both
minCapacityandmaxCapacitybut 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 schedules
Of 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:
import { TimeZone } from 'aws-cdk-lib';
declare const resource: SomeScalableResource;
const capacity = resource.autoScaleCapacity({
minCapacity: 1,
maxCapacity: 50,
});
capacity.scaleOnSchedule('PrescaleInTheMorning', {
schedule: appscaling.Schedule.cron({ hour: '8', minute: '0' }),
minCapacity: 20,
timeZone: TimeZone.AMERICA_DENVER,
});
capacity.scaleOnSchedule('AllowDownscalingAtNight', {
schedule: appscaling.Schedule.cron({ hour: '20', minute: '0' }),
minCapacity: 1,
timeZone: TimeZone.AMERICA_DENVER,
});
from aws_cdk import TimeZone
# resource: SomeScalableResource
capacity = resource.auto_scale_capacity(
min_capacity=1,
max_capacity=50
)
capacity.scale_on_schedule("PrescaleInTheMorning",
schedule=appscaling.Schedule.cron(hour="8", minute="0"),
min_capacity=20,
time_zone=TimeZone.AMERICA_DENVER
)
capacity.scale_on_schedule("AllowDownscalingAtNight",
schedule=appscaling.Schedule.cron(hour="20", minute="0"),
min_capacity=1,
time_zone=TimeZone.AMERICA_DENVER
)
import software.amazon.awscdk.TimeZone;
SomeScalableResource resource;
ScalableAttribute capacity = resource.autoScaleCapacity(new Caps()
.minCapacity(1)
.maxCapacity(50)
);
capacity.scaleOnSchedule("PrescaleInTheMorning", ScalingSchedule.builder()
.schedule(Schedule.cron(CronOptions.builder().hour("8").minute("0").build()))
.minCapacity(20)
.timeZone(TimeZone.AMERICA_DENVER)
.build());
capacity.scaleOnSchedule("AllowDownscalingAtNight", ScalingSchedule.builder()
.schedule(Schedule.cron(CronOptions.builder().hour("20").minute("0").build()))
.minCapacity(1)
.timeZone(TimeZone.AMERICA_DENVER)
.build());
using Amazon.CDK;
SomeScalableResource resource;
var capacity = resource.AutoScaleCapacity(new Caps {
MinCapacity = 1,
MaxCapacity = 50
});
capacity.ScaleOnSchedule("PrescaleInTheMorning", new ScalingSchedule {
Schedule = Schedule.Cron(new CronOptions { Hour = "8", Minute = "0" }),
MinCapacity = 20,
TimeZone = TimeZone.AMERICA_DENVER
});
capacity.ScaleOnSchedule("AllowDownscalingAtNight", new ScalingSchedule {
Schedule = Schedule.Cron(new CronOptions { Hour = "20", Minute = "0" }),
MinCapacity = 1,
TimeZone = TimeZone.AMERICA_DENVER
});
import "github.com/aws/aws-cdk-go/awscdk"
var resource someScalableResource
capacity := resource.autoScaleCapacity(&caps{
minCapacity: jsii.Number(1),
maxCapacity: jsii.Number(50),
})
capacity.scaleOnSchedule(jsii.String("PrescaleInTheMorning"), &ScalingSchedule{
Schedule: appscaling.Schedule_Cron(&CronOptions{
Hour: jsii.String("8"),
Minute: jsii.String("0"),
}),
MinCapacity: jsii.Number(20),
TimeZone: awscdk.TimeZone_AMERICA_DENVER(),
})
capacity.scaleOnSchedule(jsii.String("AllowDownscalingAtNight"), &ScalingSchedule{
Schedule: appscaling.Schedule_*Cron(&CronOptions{
Hour: jsii.String("20"),
Minute: jsii.String("0"),
}),
MinCapacity: jsii.Number(1),
TimeZone: awscdk.TimeZone_AMERICA_DENVER(),
})
import * as lambda from 'aws-cdk-lib/aws-lambda';
declare const code: lambda.Code;
const handler = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.PYTHON_3_12,
handler: 'index.handler',
code,
reservedConcurrentExecutions: 2,
});
const fnVer = handler.currentVersion;
const target = new appscaling.ScalableTarget(this, 'ScalableTarget', {
serviceNamespace: appscaling.ServiceNamespace.LAMBDA,
maxCapacity: 100,
minCapacity: 10,
resourceId: `function:${handler.functionName}:${fnVer.version}`,
scalableDimension: 'lambda:function:ProvisionedConcurrency',
})
target.scaleToTrackMetric('PceTracking', {
targetValue: 0.9,
predefinedMetric: appscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
})
import aws_cdk.aws_lambda as lambda_
# code: lambda.Code
handler = lambda_.Function(self, "MyFunction",
runtime=lambda_.Runtime.PYTHON_3_12,
handler="index.handler",
code=code,
reserved_concurrent_executions=2
)
fn_ver = handler.current_version
target = appscaling.ScalableTarget(self, "ScalableTarget",
service_namespace=appscaling.ServiceNamespace.LAMBDA,
max_capacity=100,
min_capacity=10,
resource_id=f"function:{handler.functionName}:{fnVer.version}",
scalable_dimension="lambda:function:ProvisionedConcurrency"
)
target.scale_to_track_metric("PceTracking",
target_value=0.9,
predefined_metric=appscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION
)
import software.amazon.awscdk.services.lambda.*;
Code code;
Function handler = Function.Builder.create(this, "MyFunction")
.runtime(Runtime.PYTHON_3_12)
.handler("index.handler")
.code(code)
.reservedConcurrentExecutions(2)
.build();
Version fnVer = handler.getCurrentVersion();
ScalableTarget target = ScalableTarget.Builder.create(this, "ScalableTarget")
.serviceNamespace(ServiceNamespace.LAMBDA)
.maxCapacity(100)
.minCapacity(10)
.resourceId(String.format("function:%s:%s", handler.getFunctionName(), fnVer.getVersion()))
.scalableDimension("lambda:function:ProvisionedConcurrency")
.build();
target.scaleToTrackMetric("PceTracking", BasicTargetTrackingScalingPolicyProps.builder()
.targetValue(0.9)
.predefinedMetric(PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION)
.build());
using Amazon.CDK.AWS.Lambda;
Code code;
var handler = new Function(this, "MyFunction", new FunctionProps {
Runtime = Runtime.PYTHON_3_12,
Handler = "index.handler",
Code = code,
ReservedConcurrentExecutions = 2
});
var fnVer = handler.CurrentVersion;
var target = new ScalableTarget(this, "ScalableTarget", new ScalableTargetProps {
ServiceNamespace = ServiceNamespace.LAMBDA,
MaxCapacity = 100,
MinCapacity = 10,
ResourceId = $"function:{handler.functionName}:{fnVer.version}",
ScalableDimension = "lambda:function:ProvisionedConcurrency"
});
target.ScaleToTrackMetric("PceTracking", new BasicTargetTrackingScalingPolicyProps {
TargetValue = 0.9,
PredefinedMetric = PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION
});
import "github.com/aws/aws-cdk-go/awscdk"
var code Code
handler := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
Runtime: lambda.Runtime_PYTHON_3_12(),
Handler: jsii.String("index.handler"),
Code: Code,
ReservedConcurrentExecutions: jsii.Number(2),
})
fnVer := handler.currentVersion
target := appscaling.NewScalableTarget(this, jsii.String("ScalableTarget"), &ScalableTargetProps{
ServiceNamespace: appscaling.ServiceNamespace_LAMBDA,
MaxCapacity: jsii.Number(100),
MinCapacity: jsii.Number(10),
ResourceId: fmt.Sprintf("function:%v:%v", handler.functionName, fnVer.Version),
ScalableDimension: jsii.String("lambda:function:ProvisionedConcurrency"),
})
target.ScaleToTrackMetric(jsii.String("PceTracking"), &BasicTargetTrackingScalingPolicyProps{
TargetValue: jsii.Number(0.9),
PredefinedMetric: appscaling.PredefinedMetric_LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
})
ElastiCache Redis shards scaling with target value
const shardsScalableTarget = new appscaling.ScalableTarget(this, 'ElastiCacheRedisShardsScalableTarget', {
serviceNamespace: appscaling.ServiceNamespace.ELASTICACHE,
scalableDimension: 'elasticache:replication-group:NodeGroups',
minCapacity: 2,
maxCapacity: 10,
resourceId: 'replication-group/main-cluster',
});
shardsScalableTarget.scaleToTrackMetric('ElastiCacheRedisShardsCPUUtilization', {
targetValue: 20,
predefinedMetric: appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
});
shards_scalable_target = appscaling.ScalableTarget(self, "ElastiCacheRedisShardsScalableTarget",
service_namespace=appscaling.ServiceNamespace.ELASTICACHE,
scalable_dimension="elasticache:replication-group:NodeGroups",
min_capacity=2,
max_capacity=10,
resource_id="replication-group/main-cluster"
)
shards_scalable_target.scale_to_track_metric("ElastiCacheRedisShardsCPUUtilization",
target_value=20,
predefined_metric=appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION
)
ScalableTarget shardsScalableTarget = ScalableTarget.Builder.create(this, "ElastiCacheRedisShardsScalableTarget")
.serviceNamespace(ServiceNamespace.ELASTICACHE)
.scalableDimension("elasticache:replication-group:NodeGroups")
.minCapacity(2)
.maxCapacity(10)
.resourceId("replication-group/main-cluster")
.build();
shardsScalableTarget.scaleToTrackMetric("ElastiCacheRedisShardsCPUUtilization", BasicTargetTrackingScalingPolicyProps.builder()
.targetValue(20)
.predefinedMetric(PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION)
.build());
var shardsScalableTarget = new ScalableTarget(this, "ElastiCacheRedisShardsScalableTarget", new ScalableTargetProps {
ServiceNamespace = ServiceNamespace.ELASTICACHE,
ScalableDimension = "elasticache:replication-group:NodeGroups",
MinCapacity = 2,
MaxCapacity = 10,
ResourceId = "replication-group/main-cluster"
});
shardsScalableTarget.ScaleToTrackMetric("ElastiCacheRedisShardsCPUUtilization", new BasicTargetTrackingScalingPolicyProps {
TargetValue = 20,
PredefinedMetric = PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION
});
shardsScalableTarget := appscaling.NewScalableTarget(this, jsii.String("ElastiCacheRedisShardsScalableTarget"), &ScalableTargetProps{
ServiceNamespace: appscaling.ServiceNamespace_ELASTICACHE,
ScalableDimension: jsii.String("elasticache:replication-group:NodeGroups"),
MinCapacity: jsii.Number(2),
MaxCapacity: jsii.Number(10),
ResourceId: jsii.String("replication-group/main-cluster"),
})
shardsScalableTarget.ScaleToTrackMetric(jsii.String("ElastiCacheRedisShardsCPUUtilization"), &BasicTargetTrackingScalingPolicyProps{
TargetValue: jsii.Number(20),
PredefinedMetric: appscaling.PredefinedMetric_ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
})
SageMaker variant provisioned concurrency utilization with target value
const target = new appscaling.ScalableTarget(this, 'SageMakerVariantScalableTarget', {
serviceNamespace: appscaling.ServiceNamespace.SAGEMAKER,
scalableDimension: 'sagemaker:variant:DesiredProvisionedConcurrency',
minCapacity: 2,
maxCapacity: 10,
resourceId: 'endpoint/MyEndpoint/variant/MyVariant',
});
target.scaleToTrackMetric('SageMakerVariantProvisionedConcurrencyUtilization', {
targetValue: 0.9,
predefinedMetric: appscaling.PredefinedMetric.SAGEMAKER_VARIANT_PROVISIONED_CONCURRENCY_UTILIZATION,
});
target = appscaling.ScalableTarget(self, "SageMakerVariantScalableTarget",
service_namespace=appscaling.ServiceNamespace.SAGEMAKER,
scalable_dimension="sagemaker:variant:DesiredProvisionedConcurrency",
min_capacity=2,
max_capacity=10,
resource_id="endpoint/MyEndpoint/variant/MyVariant"
)
target.scale_to_track_metric("SageMakerVariantProvisionedConcurrencyUtilization",
target_value=0.9,
predefined_metric=appscaling.PredefinedMetric.SAGEMAKER_VARIANT_PROVISIONED_CONCURRENCY_UTILIZATION
)
ScalableTarget target = ScalableTarget.Builder.create(this, "SageMakerVariantScalableTarget")
.serviceNamespace(ServiceNamespace.SAGEMAKER)
.scalableDimension("sagemaker:variant:DesiredProvisionedConcurrency")
.minCapacity(2)
.maxCapacity(10)
.resourceId("endpoint/MyEndpoint/variant/MyVariant")
.build();
target.scaleToTrackMetric("SageMakerVariantProvisionedConcurrencyUtilization", BasicTargetTrackingScalingPolicyProps.builder()
.targetValue(0.9)
.predefinedMetric(PredefinedMetric.SAGEMAKER_VARIANT_PROVISIONED_CONCURRENCY_UTILIZATION)
.build());
var target = new ScalableTarget(this, "SageMakerVariantScalableTarget", new ScalableTargetProps {
ServiceNamespace = ServiceNamespace.SAGEMAKER,
ScalableDimension = "sagemaker:variant:DesiredProvisionedConcurrency",
MinCapacity = 2,
MaxCapacity = 10,
ResourceId = "endpoint/MyEndpoint/variant/MyVariant"
});
target.ScaleToTrackMetric("SageMakerVariantProvisionedConcurrencyUtilization", new BasicTargetTrackingScalingPolicyProps {
TargetValue = 0.9,
PredefinedMetric = PredefinedMetric.SAGEMAKER_VARIANT_PROVISIONED_CONCURRENCY_UTILIZATION
});
target := appscaling.NewScalableTarget(this, jsii.String("SageMakerVariantScalableTarget"), &ScalableTargetProps{
ServiceNamespace: appscaling.ServiceNamespace_SAGEMAKER,
ScalableDimension: jsii.String("sagemaker:variant:DesiredProvisionedConcurrency"),
MinCapacity: jsii.Number(2),
MaxCapacity: jsii.Number(10),
ResourceId: jsii.String("endpoint/MyEndpoint/variant/MyVariant"),
})
target.ScaleToTrackMetric(jsii.String("SageMakerVariantProvisionedConcurrencyUtilization"), &BasicTargetTrackingScalingPolicyProps{
TargetValue: jsii.Number(0.9),
PredefinedMetric: appscaling.PredefinedMetric_SAGEMAKER_VARIANT_PROVISIONED_CONCURRENCY_UTILIZATION,
})
Types
| Name | Kind | Summary |
|---|---|---|
ScalableTarget | Construct (L2) | Define a scalable target. |
CfnScalableTarget | Construct (L1) | The AWS::ApplicationAutoScaling::ScalableTarget resource specifies a resource that Application Auto Scaling can scale, such as an AWS::DynamoDB::Table or AWS::ECS::Service resource. |
CfnScalingPolicy | Construct (L1) | The AWS::ApplicationAutoScaling::ScalingPolicy resource defines a scaling policy that Application Auto Scaling uses to adjust the capacity of a scalable target. |
AdjustmentTier | Struct | An adjustment. |
AdjustmentType | Enum | How adjustment numbers are interpreted. |
BaseScalableAttribute | Construct | Represent an attribute for which autoscaling can be configured. |
BaseScalableAttributeProps | Struct | Properties for a ScalableTableAttribute. |
BaseTargetTrackingProps | Struct | Base interface for target tracking props. |
BasicStepScalingPolicyProps | Struct | |
BasicTargetTrackingScalingPolicyProps | Struct | Properties for a Target Tracking policy that include the metric but exclude the target. |
CfnScalableTarget.ScalableTargetActionProperty | Struct | ScalableTargetAction specifies the minimum and maximum capacity for the ScalableTargetAction property of the AWS::ApplicationAutoScaling::ScalableTarget ScheduledAction property type. |
CfnScalableTarget.ScheduledActionProperty | Struct | ScheduledAction is a property of the AWS::ApplicationAutoScaling::ScalableTarget resource that specifies a scheduled action for a scalable target. |
CfnScalableTarget.SuspendedStateProperty | Struct | SuspendedState is a property of the AWS::ApplicationAutoScaling::ScalableTarget resource that specifies whether the scaling activities for a scalable target are in a suspended state. |
CfnScalableTargetProps | Struct | Properties for defining a CfnScalableTarget. |
CfnScalingPolicy.CustomizedMetricSpecificationProperty | Struct | Contains customized metric specification information for a target tracking scaling policy for Application Auto Scaling. |
CfnScalingPolicy.MetricDimensionProperty | Struct | MetricDimension specifies a name/value pair that is part of the identity of a CloudWatch metric for the Dimensions property of the AWS::ApplicationAutoScaling::ScalingPolicy CustomizedMetricSpecification property type. Duplicate dimensions are not allowed. |
CfnScalingPolicy.PredefinedMetricSpecificationProperty | Struct | Contains predefined metric specification information for a target tracking scaling policy for Application Auto Scaling. |
CfnScalingPolicy.PredictiveScalingCustomizedCapacityMetricProperty | Struct | Represents a CloudWatch metric of your choosing for a predictive scaling policy. |
CfnScalingPolicy.PredictiveScalingCustomizedLoadMetricProperty | Struct | The customized load metric specification. |
CfnScalingPolicy.PredictiveScalingCustomizedScalingMetricProperty | Struct | One or more metric data queries to provide data points for a metric specification. |
CfnScalingPolicy.PredictiveScalingMetricDataQueryProperty | Struct | The metric data to return. |
CfnScalingPolicy.PredictiveScalingMetricDimensionProperty | Struct | Describes the dimension of a metric. |
CfnScalingPolicy.PredictiveScalingMetricProperty | Struct | Describes the scaling metric. |
CfnScalingPolicy.PredictiveScalingMetricSpecificationProperty | Struct | This structure specifies the metrics and target utilization settings for a predictive scaling policy. |
CfnScalingPolicy.PredictiveScalingMetricStatProperty | Struct | This structure defines the CloudWatch metric to return, along with the statistic and unit. |
CfnScalingPolicy.PredictiveScalingPolicyConfigurationProperty | Struct | Represents a predictive scaling policy configuration. |
CfnScalingPolicy.PredictiveScalingPredefinedLoadMetricProperty | Struct | Describes a load metric for a predictive scaling policy. |
CfnScalingPolicy.PredictiveScalingPredefinedMetricPairProperty | Struct | Represents a metric pair for a predictive scaling policy. |
CfnScalingPolicy.PredictiveScalingPredefinedScalingMetricProperty | Struct | Describes a scaling metric for a predictive scaling policy. |
CfnScalingPolicy.StepAdjustmentProperty | Struct | StepAdjustment specifies a step adjustment for the StepAdjustments property of the AWS::ApplicationAutoScaling::ScalingPolicy StepScalingPolicyConfiguration property type. |
CfnScalingPolicy.StepScalingPolicyConfigurationProperty | Struct | StepScalingPolicyConfiguration is a property of the AWS::ApplicationAutoScaling::ScalingPolicy resource that specifies a step scaling policy configuration for Application Auto Scaling. |
CfnScalingPolicy.TargetTrackingMetricDataQueryProperty | Struct | The metric data to return. |
CfnScalingPolicy.TargetTrackingMetricDimensionProperty | Struct | TargetTrackingMetricDimension specifies a name/value pair that is part of the identity of a CloudWatch metric for the Dimensions property of the AWS::ApplicationAutoScaling::ScalingPolicy TargetTrackingMetric property type. Duplicate dimensions are not allowed. |
CfnScalingPolicy.TargetTrackingMetricProperty | Struct | Represents a specific metric for a target tracking scaling policy for Application Auto Scaling. |
CfnScalingPolicy.TargetTrackingMetricStatProperty | Struct | This structure defines the CloudWatch metric to return, along with the statistic and unit. |
CfnScalingPolicy.TargetTrackingScalingPolicyConfigurationProperty | Struct | TargetTrackingScalingPolicyConfiguration is a property of the AWS::ApplicationAutoScaling::ScalingPolicy resource that specifies a target tracking scaling policy configuration for Application Auto Scaling. Use a target tracking scaling policy to adjust the capacity of the specified scalable target in response to actual workloads, so that resource utilization remains at or near the target utilization value. |
CfnScalingPolicyProps | Struct | Properties for defining a CfnScalingPolicy. |
CronOptions | Struct | Options to configure a cron expression. |
EnableScalingProps | Struct | Properties for enabling Application Auto Scaling. |
IScalableTarget | Interface | |
MetricAggregationType | Enum | How the scaling metric is going to be aggregated. |
PredefinedMetric | Enum | One of the predefined autoscaling metrics. |
ScalableTargetAttributes | Struct | Attributes for importing a scalable target. |
ScalableTargetProps | Struct | Properties for a scalable target. |
ScalingInterval | Struct | A range of metric values in which to apply a certain scaling operation. |
ScalingSchedule | Struct | A scheduled scaling action. |
Schedule | Class | Schedule for scheduled scaling actions. |
ServiceNamespace | Enum | The service that supports Application AutoScaling. |
StepScalingAction | Construct | Define a step scaling action. |
StepScalingActionProps | Struct | Properties for a scaling policy. |
StepScalingPolicy | Construct | Define a scaling strategy which scales depending on absolute values of some metric. |
StepScalingPolicyProps | Struct | |
TargetTrackingScalingPolicy | Construct | |
TargetTrackingScalingPolicyProps | Struct | Properties for a concrete TargetTrackingPolicy. |