Introducing a new way to review your PRs.

Read the announcement

floci-io / floci

Light, fluffy, and always free - The AWS Local Emulator alternative

View on GitHub

38 documents · Updated Nov 23, 2026

docs / svc-application-autoscaling

Application Auto Scaling

Application Auto Scaling provides an AWS-shaped control plane for resources that can change capacity. It stores scalable targets, scaling policies, scheduled actions, and activity history. It connects policy alarms to capacity changes and currently applies those changes to ECS service desired counts.

Scalable-target state

A scalable target defines the resource identity, capacity range, role, tags, and control state used by scaling. Its identity is the combination of service namespace, resource ID, and scalable dimension. State is regional, and re-registering a target changes only the values supplied by the caller.

The target has separate switches for dynamic scale-in, dynamic scale-out, and scheduled scaling. Its stable target ARN supports tag operations. When no role ARN is supplied, the service creates the corresponding service-linked role ARN shape.

References: src/…/ApplicationAutoScalingService.java• L142-203 src/…/ScalableTarget.java• L21-95

Scaling-policy state

A scaling policy attaches a capacity rule to an existing scalable target. The service accepts step scaling, target tracking, and predictive policy types. It stores the policy configuration, policy ARN, target identity, owned alarm records, and state used for cooldown decisions.

Target tracking creates one high alarm and one low alarm in CloudWatch. Replacing or deleting the policy removes its owned alarms. Step scaling has no service-created alarm, but an external alarm can invoke it through the policy ARN. Policy configuration is exposed through the API and remains aligned with CloudFormation input.

References: src/…/ApplicationAutoScalingService.java• L510-607 src/…/ApplicationAutoScalingJsonHandler.java• L218-263 src/…/ApplicationAutoScalingService.java• L664-705

Scheduled-action state

A scheduled action is a retained one-off capacity-bound change for a scalable target. The current service supports ECS desired count targets and UTC at(yyyy-MM-ddTHH:mm:ss) schedules. The action stores optional minimum and maximum capacity bounds and moves through pending, claimed, succeeded, failed, or skipped state.

The scheduler restores overdue pending or claimed actions as skipped after restart. It then claims due actions in deadline order. A due action updates the target bounds and clamps the current ECS capacity to those bounds. Missing targets, scheduled-scaling suspension, or execution errors prevent the capacity change and produce a skipped or failed result.

This diagram shows how a stored one-off action moves from recovery to a bounded ECS capacity change.

flowchart LR
    S[Stored scheduled action] --> R[Startup recovery]
    R -->|overdue or claimed| K[Skipped]
    R -->|pending and due| C[Claim action]
    C --> T[Check target and suspension]
    T -->|blocked| K
    T -->|allowed| B[Apply capacity bounds]
    B --> E[Adjust ECS desired count]
    E --> O[Succeeded or failed]
    O --> H[Scaling activity]

References: src/…/ApplicationAutoScalingService.java• L261-355 src/…/ApplicationAutoScalingService.java• L397-506 src/…/ApplicationAutoScalingScheduledActionScheduler.java• L15-41 src/…/ScheduledAction.java• L7-77

Alarm-driven capacity adjustment

CloudWatch alarms connect observed metrics to scaling policies. When an alarm action names a policy ARN, the handler resolves the policy and target, computes a new capacity, applies target bounds and control switches, and sends the change to the matching capacity integration.

Target tracking derives capacity from the observed value and target value. Step scaling selects the rule whose interval contains the value's difference from the alarm threshold. Both modes stop when the final capacity is unchanged, respect minimum and maximum bounds, and block scale-in when policy or target state disables it.

Cooldowns apply separately to scale-in and scale-out. A persistent alarm is checked again on later evaluator passes, so a deferred action can run after cooldown. A scale-out can proceed during cooldown when it moves above the last scale-out capacity or when capacity changed outside the policy. Successful changes update policy state and create a scaling activity.

This diagram shows how a metric breach becomes a capacity update or remains only an observed alarm event.

sequenceDiagram
    participant M as CloudWatch metric
    participant A as CloudWatch alarm
    participant E as Alarm evaluator
    participant P as Scaling policy
    participant R as Capacity integration
    participant H as Activity history

    M->>A: Breach policy threshold
    A->>E: Remain in ALARM
    E->>P: Send policy ARN and value
    P->>P: Compute and bound capacity
    P->>P: Check suspension and cooldown
    alt Action allowed
        P->>R: Set capacity
        P->>H: Record successful activity
    else Action blocked or unchanged
        P-->>E: Wait for a later evaluation
    end

The alarm metric identity matters. ECS target-tracking alarms use the ECS service dimensions, while customized specifications preserve the caller's metric details. Predefined ECS and Application Load Balancer metrics map to the CloudWatch metrics published by those services. Other accepted namespaces can retain policy state without changing capacity when no matching integration exists.

References: src/…/ScalingPolicyAlarmActionHandler.java• L77-166 src/…/ScalingPolicyAlarmActionHandler.java• L190-284 src/…/ApplicationAutoScalingService.java• L669-835

ECS capacity integration

ECS is the active capacity integration for Application Auto Scaling. An ECS target uses a resource ID in the form service/<cluster>/<service>, and a successful scaling action changes the ECS service desired count.

ECS then reconciles the desired count by starting or stopping service tasks. Application Auto Scaling controls the desired count, while ECS makes the running task set match it. Other accepted scalable dimensions remain control-plane state unless a matching capacity integration is available. See container orchestration for the wider ECS service lifecycle.

References: src/…/ScalingPolicyAlarmActionHandler.java• L107-112 src/…/ApplicationAutoScalingService.java• L713-721 src/…/EcsService.java• L847-889 src/…/EcsService.java• L1760-1823

Scaling activity history

Scaling activities record capacity changes made by dynamic or scheduled scaling. Each record identifies the target and includes a description, cause, start and end times, status, and an optional failure message.

The history is regional and can be filtered by target identity. Results are newest first. Blocked alarms and actions that do not change capacity do not create a successful dynamic activity, while scheduled actions record their succeeded or failed execution result.

References: src/…/ApplicationAutoScalingService.java• L499-506 src/…/ApplicationAutoScalingService.java• L1025-1062 src/…/ApplicationAutoScalingJsonHandler.java• L265-275

API boundary

The Application Auto Scaling API exposes target registration and discovery, scheduled-action management, policy management, activity discovery, and target tagging. The JSON boundary routes these actions to the control plane and preserves omitted optional fields in policy and scheduled-action responses.

Target and policy relationships are checked before state is created. Described targets include suspension state and a target ARN for tag operations. Scheduled actions and list operations support signed pagination tokens, while unsupported operations return an API error instead of creating partial state. See CloudWatch for the alarm and metric system that drives policy actions.

References: src/…/ApplicationAutoScalingJsonHandler.java• L53-72 src/…/ApplicationAutoScalingJsonHandler.java• L77-175 src/…/ApplicationAutoScalingJsonHandler.java• L218-339

Change checklist

When these files or sections are changed, remember to consider these:

  • If scheduled-action states or recovery rules change, preserve the no-replay behavior for overdue and claimed actions.
  • If scheduled capacity bounds change, keep target bounds and the ECS desired count update consistent.
  • If target-tracking alarm identity changes, keep metric dimensions, policy replacement, alarm cleanup, and alarm dispatch aligned.
  • If cooldown state changes, keep the last applied capacity separate from the last scale-out capacity.
  • If a scalable dimension gains a capacity integration, align its resource ID rules with the owning service update API.
  • If target or policy fields change, keep stored state and API response fields aligned.
  • If the API adds a scheduled-action field, preserve the distinction between an omitted field and an explicit value.

Important failure modes

TriggerConsequenceGuard
A policy references an unregistered targetThe policy is rejected and cannot receive a scaling actionPolicy creation checks the target identity first
A target-tracking policy is replaced without removing its old alarmsOld alarms can create duplicate policy actionsReplacement deletes the owned alarm pair before creating new alarms
A scheduled action is restored after its deadlineThe action could apply an old capacity changeStartup recovery marks overdue pending and claimed actions as skipped
A scheduled action runs while scheduled scaling is suspendedThe scheduled capacity change must not applyExecution checks the target's scheduled-scaling suspension state
An alarm targets a dimension without a capacity integrationThe policy remains visible but capacity does not changeProvide a matching capacity integration for the dimension
An ECS resource ID does not use service/<cluster>/<service>ECS capacity lookup failsThe ECS integration validates and parses the resource ID
An alarm remains in ALARM during cooldownThe action waits for a later evaluator passPersistent alarm states are checked on each scheduled pass
API and CloudFormation policy fields are parsed differentlyThe same policy can produce different state by entry pointBoth callers use the shared policy configuration parser

Key files

FileWhy to read it
src/…/ApplicationAutoScalingService.javaTarget, policy, scheduled-action, alarm, tag, role, and activity relationships
src/…/ScalableTarget.javaTarget identity, capacity range, suspension, and tag state
src/…/ScheduledAction.javaOne-off action fields and execution states
src/…/ScalingPolicyAlarmActionHandler.javaAlarm-to-capacity rules, bounds, suspension, and cooldown guards
src/…/ApplicationAutoScalingScheduledActionScheduler.javaStartup recovery and scheduled-action sweep lifecycle
src/…/ApplicationAutoScalingJsonHandler.javaAPI action routing, validation, pagination, and response shape
src/…/EcsCapacityAdjuster.javaECS resource resolution and desired-count changes
src/…/AlarmEvaluator.javaMetric alarm evaluation and repeated action dispatch
src/…/EcsService.javaECS desired-count reconciliation into service tasks
src/…/ScalingActivity.javaActivity records returned by activity discovery