diff --git a/moto/iot/models.py b/moto/iot/models.py index 258a387fe..4a7d43239 100644 --- a/moto/iot/models.py +++ b/moto/iot/models.py @@ -924,8 +924,12 @@ class IoTBackend(BaseBackend): + thing_group_name + " when there are still child groups attached to it" ) - thing_group = self.describe_thing_group(thing_group_name) - del self.thing_groups[thing_group.arn] + try: + thing_group = self.describe_thing_group(thing_group_name) + del self.thing_groups[thing_group.arn] + except ResourceNotFoundException: + # AWS returns success even if the thing group does not exist. + pass def list_thing_groups(self, parent_group, name_prefix_filter, recursive): if recursive is None: diff --git a/tests/test_iot/test_iot.py b/tests/test_iot/test_iot.py index 7a04cdc16..e80a12a0f 100644 --- a/tests/test_iot/test_iot.py +++ b/tests/test_iot/test_iot.py @@ -1038,11 +1038,15 @@ def test_delete_thing_group(): res.should.have.key("thingGroups").which.should.have.length_of(1) res["thingGroups"].should_not.have.key(group_name_2a) - # now that there is no child group, we can delete the previus group safely + # now that there is no child group, we can delete the previous group safely client.delete_thing_group(thingGroupName=group_name_1a) res = client.list_thing_groups() res.should.have.key("thingGroups").which.should.have.length_of(0) + # Deleting an invalid thing group does not raise an error. + res = client.delete_thing_group(thingGroupName="non-existent-group-name") + res["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + @mock_iot def test_describe_thing_group_metadata_hierarchy():