floci-io/floci · error · AwsException
ResourceInUse
ResourceInUse
Error message
Auto Scaling group '{name}' has {count} instance(s). Set ForceDelete=true to delete anyway. What it means
Thrown by deleteAutoScalingGroup when the group still has instances not in the Terminated lifecycle state and ForceDelete is not set. Amazon EC2 Auto Scaling refuses to delete non-empty groups to prevent orphaned instances; ForceDelete=true terminates the members first. Floci reproduces this as ResourceInUse (HTTP 400), matching AWS.
Source
Thrown at src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingService.java:282
if (minSize != null) { asg.setMinSize(minSize); }
if (maxSize != null) { asg.setMaxSize(maxSize); }
if (desiredCapacity != null) { asg.setDesiredCapacity(desiredCapacity); }
if (defaultCooldown != null) { asg.setDefaultCooldown(defaultCooldown); }
if (availabilityZones != null) { asg.setAvailabilityZones(new ArrayList<>(availabilityZones)); }
if (subnetIds != null) { asg.setSubnetIds(new ArrayList<>(subnetIds)); }
if (healthCheckType != null) { asg.setHealthCheckType(healthCheckType); }
if (healthCheckGracePeriod != null) { asg.setHealthCheckGracePeriod(healthCheckGracePeriod); }
if (terminationPolicies != null) { asg.setTerminationPolicies(new ArrayList<>(terminationPolicies)); }
groups.put(asgKey(region, name), asg);
}
public void deleteAutoScalingGroup(String region, String name, boolean forceDelete) {
AutoScalingGroup asg = requireGroup(region, name);
List<AsgInstance> active = asg.getInstances().stream()
.filter(i -> !"Terminated".equals(i.getLifecycleState()))
.collect(Collectors.toList());
if (!active.isEmpty() && !forceDelete) {
throw new AwsException("ResourceInUse",
"Auto Scaling group '" + name + "' has " + active.size()
+ " instance(s). Set ForceDelete=true to delete anyway.", 400);
}
if (forceDelete && ec2Service != null && !active.isEmpty()) {
active.stream()
.map(AsgInstance::getInstanceId)
.filter(Objects::nonNull)
.forEach(instanceId -> {
try {
ec2Service.terminateInstances(region, List.of(instanceId));
}
catch (AwsException ignored) {
// ForceDelete should remove stale ASG membership even if EC2 no longer has the instance.
}
});
}
groups.remove(asgKey(region, name));
// clean up associated hooks and policiesView on GitHub (pinned to 62ff490619)
Solutions
- Set desired capacity to 0 (UpdateAutoScalingGroup with DesiredCapacity=0), wait for instances to reach Terminated, then delete
- Or set ForceDelete=true on the DeleteAutoScalingGroup call, which terminates instances and deletes the group
- For graceful teardown: detach instances with ShouldDecrementDesiredCapacity=true, wait, then delete
Example fix
// before
DeleteAutoScalingGroupRequest req = DeleteAutoScalingGroupRequest.builder()
.autoScalingGroupName(asgName)
.build();
// after
DeleteAutoScalingGroupRequest req = DeleteAutoScalingGroupRequest.builder()
.autoScalingGroupName(asgName)
.forceDelete(true)
.build(); Defensive patterns
Strategy: validation
Validate before calling
Group g = autoscaling.describeAutoScalingGroups(DescribeAutoScalingGroupsRequest.builder()
.autoScalingGroupNames(asgName).build())
.autoScalingGroups().get(0);
long active = g.instances().stream()
.filter(i -> !"Terminated".equals(i.lifecycleState())).count();
if (active > 0) {
// scale in first, or set forceDelete(true) on the delete request
} Try / catch
catch (ResourceInUseException e) { log.warn("ASG {} not empty", asgName); retryWithForceDelete or scaleInFirst(); } Prevention
- Scale groups to DesiredCapacity=0 before deletion in teardown scripts
- Treat ResourceInUse as a retryable-with-action signal, not a hard failure
When it happens
Trigger: Calling DeleteAutoScalingGroup with the group's AutoScalingGroupName while desiredCapacity > 0 or any instance is InService/Pending/Standby, without setting ForceDelete=true.
Common situations: Tearing down test stacks without scaling the group to zero first; cleanup scripts that assume delete is unconditional; instances mid-launch from a recent scale-out; standby instances that never terminated.
Related errors
- InvalidRequestException
- ResourceInUseException
- InvalidRequestException
- InstanceRefreshInProgress
- InvalidNextToken
AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14).
Data as JSON: /api/errors/869e2876f5c98ace.
Report an issue: GitHub.