Skip to content

AWS.ApplicationAutoScaling reference

Source: src/AWS/ApplicationAutoScaling/DescribeScalingActivities.ts

Runtime binding for the DescribeScalingActivities operation (IAM action application-autoscaling:DescribeScalingActivities).

Returns the scalable target’s scaling activities from the previous six weeks — what scaled, when, why, and whether it succeeded — including not-scaled reasons when IncludeNotScaledActivities is set. Provide the implementation with Effect.provide(AWS.ApplicationAutoScaling.DescribeScalingActivitiesHttp).

DescribeScalingActivities: Observing Scaling Activity

Section titled “DescribeScalingActivities: Observing Scaling Activity”

List Recent Scaling Activities

// init — bind the operation to the scalable target
const describeScalingActivities =
yield* AWS.ApplicationAutoScaling.DescribeScalingActivities(target);
// runtime — page through the target's recent activities
const page = yield* describeScalingActivities({ MaxResults: 50 });
for (const activity of page.ScalingActivities ?? []) {
yield* Effect.log(`${activity.StatusCode}: ${activity.Description}`);
}

Include Not-Scaled Reasons

const page = yield* describeScalingActivities({
IncludeNotScaledActivities: true,
});

Source: src/AWS/ApplicationAutoScaling/GetPredictiveScalingForecast.ts

Runtime binding for the GetPredictiveScalingForecast operation (IAM action application-autoscaling:GetPredictiveScalingForecast).

Retrieves the load and capacity forecast a predictive scaling policy has computed for a time window (forecasts are created from at least 24 hours of historical CloudWatch data). The bound policy must be a PredictiveScaling policy on an ECS service: the API rejects other policy types with the typed ValidationException and namespaces without predictive scaling support with the typed PredictiveScalingForecastNotSupported. Provide the implementation with Effect.provide(AWS.ApplicationAutoScaling.GetPredictiveScalingForecastHttp).

GetPredictiveScalingForecast: Reading Forecasts

Section titled “GetPredictiveScalingForecast: Reading Forecasts”
// init — bind the operation to the predictive scaling policy
const getPredictiveScalingForecast =
yield* AWS.ApplicationAutoScaling.GetPredictiveScalingForecast(policy);
// runtime — read the forecast window
const now = yield* Effect.sync(() => Date.now());
const forecast = yield* getPredictiveScalingForecast({
StartTime: new Date(now),
EndTime: new Date(now + 48 * 60 * 60 * 1000),
});
const capacity = forecast.CapacityForecast?.Values ?? [];

Source: src/AWS/ApplicationAutoScaling/ScalableTarget.ts

An Application Auto Scaling scalable target — registers a resource’s capacity dimension (an ECS service’s desired count, a DynamoDB table’s read capacity, Lambda provisioned concurrency, …) so that scaling policies and scheduled actions can act on it.

A scalable target is uniquely identified by the (serviceNamespace, resourceId, scalableDimension) triple; changing any part of the triple replaces the target. Deregistering a scalable target deletes the scaling policies and scheduled actions associated with it.

Scale an ECS Service

const target = yield* ScalableTarget("ApiScaling", {
serviceNamespace: "ecs",
resourceId: Output.interpolate`service/${cluster.clusterName}/${service.serviceName}`,
scalableDimension: "ecs:service:DesiredCount",
minCapacity: 1,
maxCapacity: 3,
});

Scale DynamoDB Read Capacity

const target = yield* ScalableTarget("TableReadScaling", {
serviceNamespace: "dynamodb",
resourceId: Output.interpolate`table/${table.tableName}`,
scalableDimension: "dynamodb:table:ReadCapacityUnits",
minCapacity: 1,
maxCapacity: 10,
});
yield* ScalableTarget("ApiScaling", {
serviceNamespace: "ecs",
resourceId: Output.interpolate`service/${cluster.clusterName}/${service.serviceName}`,
scalableDimension: "ecs:service:DesiredCount",
minCapacity: 1,
maxCapacity: 3,
suspendedState: { DynamicScalingInSuspended: true },
});

Source: src/AWS/ApplicationAutoScaling/ScalingPolicy.ts

An Application Auto Scaling scaling policy attached to a scalable target.

Supports TargetTrackingScaling (Application Auto Scaling creates and manages the CloudWatch alarms) and StepScaling (you attach the policy to your own alarm). The policy applies to the scalable target identified by the (serviceNamespace, resourceId, scalableDimension) triple, which must be registered (see ScalableTarget) before the policy is created — pass the target’s outputs so deployment orders correctly.

Track ECS Service CPU

const target = yield* ScalableTarget("ApiScaling", {
serviceNamespace: "ecs",
resourceId: Output.interpolate`service/${cluster.clusterName}/${service.serviceName}`,
scalableDimension: "ecs:service:DesiredCount",
minCapacity: 1,
maxCapacity: 3,
});
yield* ScalingPolicy("ApiCpuPolicy", {
serviceNamespace: target.serviceNamespace,
resourceId: target.resourceId,
scalableDimension: target.scalableDimension,
targetTracking: {
TargetValue: 60,
PredefinedMetricSpecification: {
PredefinedMetricType: "ECSServiceAverageCPUUtilization",
},
ScaleOutCooldown: 60,
ScaleInCooldown: 60,
},
});

Track a Customized Metric

yield* ScalingPolicy("QueueDepthPolicy", {
serviceNamespace: target.serviceNamespace,
resourceId: target.resourceId,
scalableDimension: target.scalableDimension,
targetTracking: {
TargetValue: 100,
CustomizedMetricSpecification: {
MetricName: "ApproximateNumberOfMessagesVisible",
Namespace: "AWS/SQS",
Dimensions: [{ Name: "QueueName", Value: "my-queue" }],
Statistic: "Average",
},
},
});
yield* ScalingPolicy("ApiStepPolicy", {
serviceNamespace: target.serviceNamespace,
resourceId: target.resourceId,
scalableDimension: target.scalableDimension,
stepScaling: {
AdjustmentType: "ChangeInCapacity",
Cooldown: 60,
MetricAggregationType: "Average",
StepAdjustments: [
{ MetricIntervalLowerBound: 0, ScalingAdjustment: 1 },
],
},
});

Source: src/AWS/ApplicationAutoScaling/ScheduledAction.ts

An Application Auto Scaling scheduled action — adjusts a scalable target’s minimum and/or maximum capacity on a one-time (at(...)) or recurring (cron(...) / rate(...)) schedule.

The action applies to the scalable target identified by the (serviceNamespace, resourceId, scalableDimension) triple, which must be registered (see ScalableTarget) before the action is created — pass the target’s outputs so deployment orders correctly.

ScheduledAction: Scheduling Capacity Changes

Section titled “ScheduledAction: Scheduling Capacity Changes”

Scale Out for Business Hours

yield* ScheduledAction("BusinessHoursScaleOut", {
serviceNamespace: target.serviceNamespace,
resourceId: target.resourceId,
scalableDimension: target.scalableDimension,
schedule: "cron(0 8 ? * MON-FRI *)",
timezone: "America/Los_Angeles",
scalableTargetAction: { MinCapacity: 3, MaxCapacity: 10 },
});

One-Time Capacity Bump

yield* ScheduledAction("LaunchDayBump", {
serviceNamespace: target.serviceNamespace,
resourceId: target.resourceId,
scalableDimension: target.scalableDimension,
schedule: "at(2030-01-01T00:00:00)",
scalableTargetAction: { MinCapacity: 5 },
});