Files
floci/docs/services/autoscaling.md
T
lex00 cebb011a00 fix(autoscaling): round-trip the dropped Auto Scaling group fields (#3494)
* fix(autoscaling): round-trip the dropped Auto Scaling group fields

CreateAutoScalingGroup and UpdateAutoScalingGroup accepted DesiredCapacityType,
CapacityRebalance, MaxInstanceLifetime and DefaultInstanceWarmup and threw them
away, so DescribeAutoScalingGroups never read them back. A mixed instances policy
launch template override that selected instance types by InstanceRequirements
instead of by name was dropped the same way, and because the override parser used
InstanceType's presence as its only "is there another override" signal, such an
override also truncated the whole Overrides list.

The four scalar members now travel into AutoScalingService as one AsgOptionalFields
record and are stored on AutoScalingGroup as boxed, uninitialised fields, so a group
that never set one omits it from the Describe response rather than reporting a
default. Update keeps its partial-update semantics: an absent member leaves the
stored value alone. DefaultInstanceWarmup honours the documented -1 removal
sentinel, MaxInstanceLifetime must be 0 or at least 86400, and DesiredCapacityType
is checked against units, vcpu and memory-mib.

LaunchTemplateOverrides.InstanceRequirements parses and echoes every member of the
botocore shape except BaselinePerformanceFactors, and an override that sets both
InstanceType and InstanceRequirements raises ValidationError as AWS does.

Verified against botocore autoscaling/2011-01-01/service-2.json from awscli 2.35.24.

* fix(autoscaling): enforce the attribute-based instance selection rules

Two rules that botocore states but does not encode as constraints were missing.

DesiredCapacityType is typed XmlStringMaxLen255 with no enum, and
CreateAutoScalingGroupType.members.DesiredCapacityType.documentation carries the
rule: "Amazon EC2 Auto Scaling supports DesiredCapacityType for attribute-based
instance type selection only." Floci accepted vcpu and memory-mib for a group
whose launch template names a fixed instance type. Both values now raise
ValidationError unless the mixed instances policy left in effect by the request
carries a launch template override with a non-empty InstanceRequirements. units
is the documented default and stays legal everywhere, and an absent member is
not validated.

The effective policy is the one the request supplies on create. On update it is
the policy the request supplies, the stored policy when the request names no
launch source, or none when the request switches the group to a launch
configuration or a plain launch template. The effective DesiredCapacityType is
likewise the request value or, when absent, the stored one, so an update cannot
strip attribute-based selection out from under a stored vcpu.

shapes.InstanceRequirements.required is ["VCpuCount", "MemoryMiB"] and the shape
documentation repeats it as "You must specify VCpuCount and MemoryMiB". An
override carrying InstanceRequirements without both ranges was stored and
returned 200; it now raises ValidationError. Both rules run on create and on
update.

createGroupCarryingEveryOptionalField is @Order(1) and seeds the group the later
ordered tests reuse, so its setup moved from a launch template naming t3.micro
to a mixed instances policy whose override sets VCpuCount and MemoryMiB. That
makes its DesiredCapacityType=vcpu legal without relaxing any assertion, and the
ordered updates that follow still see attribute-based selection in effect.
2026-09-12 18:37:36 -05:00

10 KiB

Auto Scaling

Floci implements the EC2 Auto Scaling API — stored-state management for launch configurations, auto scaling groups, lifecycle hooks, and scaling policies, plus a real capacity reconciler that launches and terminates EC2 instances to maintain desired capacity.

Protocol: Query — POST / with Action= form parameter, credential scope autoscaling

ARN formats:

  • arn:aws:autoscaling:<region>:<account>:autoScalingGroup:<uuid>:autoScalingGroupName/<name>
  • arn:aws:autoscaling:<region>:<account>:launchConfiguration:<uuid>:launchConfigurationName/<name>
  • arn:aws:autoscaling:<region>:<account>:scalingPolicy:<uuid>:autoScalingGroupName/<group>/policyName/<name>

Supported Operations (45 total)

Launch Configurations

Operation Notes
CreateLaunchConfiguration Stores template: ImageId, InstanceType, KeyName, SecurityGroups, UserData, IamInstanceProfile, InstanceMonitoring, BlockDeviceMappings
DescribeLaunchConfigurations Filtered by name list; returns all if no filter
DeleteLaunchConfiguration Removes the named launch configuration

Auto Scaling Groups

Operation Notes
CreateAutoScalingGroup Creates a group with min/max/desired capacity, AZs, tags, launch configuration, launch template, or mixed instances policy; starts capacity reconciliation loop
DescribeAutoScalingGroups Filtered by name list; returns all if no filter; includes current instance list with lifecycle state and mixed instances policy shape when configured
UpdateAutoScalingGroup Updates capacity bounds, cooldown, launch source, AZs
DeleteAutoScalingGroup ForceDelete=true terminates all instances before deletion

Instance Management

Operation Notes
DescribeAutoScalingInstances Returns all ASG-tracked instances with lifecycle state and health status
SetDesiredCapacity Updates desired count; reconciler handles scale-out / scale-in within 10 s
AttachInstances Attaches existing EC2 instances to a group; sets lifecycle state to InService
DetachInstances Detaches instances from a group; optionally decrements desired capacity
TerminateInstanceInAutoScalingGroup Terminates a specific instance; optionally decrements desired capacity
SuspendProcesses Records suspended scaling processes (empty list suspends all); reported back by DescribeAutoScalingGroups
ResumeProcesses Clears suspended processes (empty list resumes all)

Load Balancer Attachment

Operation Notes
AttachLoadBalancerTargetGroups Attaches ELB v2 target group ARNs; new instances auto-registered on InService
DetachLoadBalancerTargetGroups Detaches target groups; instances deregistered
DescribeLoadBalancerTargetGroups Lists target groups attached to a group
AttachLoadBalancers Classic ELB attachment (stored; no ELB v1 routing)
DetachLoadBalancers Classic ELB detachment
DescribeLoadBalancers Lists classic ELBs attached to a group

Traffic Sources

Operation Notes
AttachTrafficSources Unified elb/elbv2/vpc-lattice attachment API; stored per identifier with its type
DetachTrafficSources Removes a traffic source by identifier
DescribeTrafficSources Lists attached sources, optionally filtered by type; every source reports InService

Lifecycle Hooks

Operation Notes
PutLifecycleHook Creates or updates a hook: LifecycleTransition, DefaultResult, HeartbeatTimeout
DescribeLifecycleHooks Lists hooks for a group
DeleteLifecycleHook Removes a hook
CompleteLifecycleAction Signals CONTINUE or ABANDON for a pending lifecycle action
RecordLifecycleActionHeartbeat Extends the heartbeat timeout for an in-progress lifecycle action

Scaling Policies

Operation Notes
PutScalingPolicy Creates or updates a policy: SimpleScaling fields or TargetTrackingScaling with predefined metric, target value, and estimated warmup
DescribePolicies Lists policies filtered by group or policy name, including stored target tracking configuration
DeletePolicy Removes a scaling policy

Scheduled Actions

Operation Notes
PutScheduledUpdateGroupAction Creates or updates a schedule: recurrence, time zone, start/end time, capacity bounds
DescribeScheduledActions Lists scheduled actions filtered by group or action name
DeleteScheduledAction Removes a scheduled action

Warm Pools

Operation Notes
PutWarmPool Full replace per the wire model: omitted fields reset to defaults; MaxGroupPreparedCapacity=-1 clears the value
DescribeWarmPool Returns the stored configuration; also embedded in DescribeAutoScalingGroups per the AutoScalingGroup shape
DeleteWarmPool Removes the configuration; idempotent when none exists

Activities

Operation Notes
DescribeScalingActivities Returns the activity log for a group; activities recorded on scale-out and scale-in events

Metadata

Operation Notes
DescribeTerminationPolicyTypes Returns the standard termination policy names
DescribeAccountLimits Returns max group / config / instance limits
DescribeLifecycleHookTypes Returns autoscaling:EC2_INSTANCE_LAUNCHING and autoscaling:EC2_INSTANCE_TERMINATING
DescribeAdjustmentTypes Returns the four standard adjustment types
DescribeMetricCollectionTypes Returns standard metric and granularity names
DescribeAutoScalingNotificationTypes Returns all notification type names

Capacity Reconciler (Phase 2)

Floci runs a background reconciler (10 s fixed rate) that keeps each group's InService instance count aligned with DesiredCapacity:

  • Scale-out: calls RunInstances with the group's launch configuration; new instances are tracked as Pending until the EC2 state transitions to running, at which point they move to InService and are registered with all attached ELB v2 target groups.
  • Scale-in: selects InService instances not protected from scale-in, deregisters them from target groups, then calls TerminateInstances.
  • Activity records are written on each scale-out and scale-in event.

Launch Source Compatibility

Auto Scaling groups preserve either a launch configuration, a top-level launch template, or a MixedInstancesPolicy. These launch sources are mutually exclusive in create/update requests. When a mixed instances policy is supplied, Floci stores and returns:

  • LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId
  • LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateName
  • LaunchTemplate.LaunchTemplateSpecification.Version
  • LaunchTemplate.Overrides.member.N.InstanceType
  • LaunchTemplate.Overrides.member.N.InstanceRequirements
  • InstancesDistribution.OnDemandBaseCapacity
  • InstancesDistribution.OnDemandPercentageAboveBaseCapacity
  • InstancesDistribution.SpotAllocationStrategy

An override selects instance types either by name or by attribute. Setting both InstanceType and InstanceRequirements on the same override raises ValidationError, matching AWS. An override that specifies InstanceRequirements must specify both VCpuCount and MemoryMiB, the two members the AWS model marks required on that shape, and raises ValidationError otherwise. Every member of the InstanceRequirements shape round-trips except BaselinePerformanceFactors, which is accepted and dropped.

A group uses attribute-based instance type selection when the mixed instances policy left in effect by the request carries at least one launch template override with InstanceRequirements. On create that is the policy the request supplies. On update it is the policy the request supplies, the stored policy when the request names no launch source, or none when the request switches the group to a launch configuration or a plain launch template.

Optional Group Fields

CreateAutoScalingGroup and UpdateAutoScalingGroup both accept the fields below, and DescribeAutoScalingGroups returns each one only when the group has a value for it. A group that never set a field omits it from the response rather than reporting a default.

Field Notes
DesiredCapacityType One of units, vcpu, memory-mib. Any other value raises ValidationError. AWS supports it for attribute-based instance type selection only, so vcpu and memory-mib raise ValidationError unless the effective mixed instances policy uses InstanceRequirements. units is the documented default and is always accepted
CapacityRebalance Stored and echoed as a boolean
MaxInstanceLifetime Seconds. Must be 0 or at least 86400. 0 means no maximum and is echoed back as 0
DefaultInstanceWarmup Seconds. Pass -1 to remove a value already set, after which the field is omitted again

Scaling Policy Compatibility

Target tracking policies preserve TargetTrackingConfiguration for predefined metrics. DescribePolicies returns PredefinedMetricSpecification.PredefinedMetricType, TargetValue, and EstimatedInstanceWarmup when present.

Configuration

Variable Default Description
FLOCI_SERVICES_AUTOSCALING_ENABLED true Enable or disable the service

Usage Example

# Create a launch configuration
aws autoscaling create-launch-configuration \
  --launch-configuration-name my-lc \
  --image-id ami-12345678 \
  --instance-type t3.micro

# Create a group targeting desired=2
aws autoscaling create-auto-scaling-group \
  --auto-scaling-group-name my-asg \
  --launch-configuration-name my-lc \
  --min-size 1 \
  --max-size 5 \
  --desired-capacity 2 \
  --availability-zones us-east-1a

# Attach an ELB v2 target group
aws autoscaling attach-load-balancer-target-groups \
  --auto-scaling-group-name my-asg \
  --target-group-arns arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/my-tg/abc123

# Watch instances appear
aws autoscaling describe-auto-scaling-groups \
  --auto-scaling-group-names my-asg

# Scale out
aws autoscaling set-desired-capacity \
  --auto-scaling-group-name my-asg \
  --desired-capacity 3