Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions moto/autoscaling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,11 @@ def describe_auto_scaling_groups(
return groups

def delete_auto_scaling_group(self, group_name: str) -> None:
if group_name not in self.autoscaling_groups:
raise ValidationError(
f"AutoScalingGroup name not found - AutoScalingGroup '{group_name}' not found"
)

self.set_desired_capacity(group_name, 0)
self.autoscaling_groups.pop(group_name, None)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_autoscaling/test_autoscaling_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from unittest import TestCase

import boto3
import pytest
from botocore.exceptions import ClientError

from moto import mock_aws
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
Expand Down Expand Up @@ -87,6 +89,16 @@ def test_autoscaling_group_delete(self):
groups = self.as_client.describe_auto_scaling_groups()["AutoScalingGroups"]
assert len(groups) == 0

with pytest.raises(ClientError) as exc:
self.as_client.delete_auto_scaling_group(AutoScalingGroupName="invalid")
err = exc.value.response["Error"]
assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400
assert err["Code"] == "ValidationError"
assert (
err["Message"]
== "AutoScalingGroup name not found - AutoScalingGroup 'invalid' not found"
)

def test_describe_autoscaling_groups__instances(self):
self._create_group(name="test_asg")

Expand Down
Loading