From 44a0d03c2547218bcff01458af9f4bf0bf0fe970 Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Sat, 28 Nov 2026 17:32:01 -0600 Subject: [PATCH] fix(config): name the delivery channel in describe and delete errors (#9692) Signed-off-by: Jackson Price --- .../sdk-test-python/tests/test_config.py | 29 +++++++++++++++---- .../configservice/AwsConfigService.java | 28 ++++++++---------- .../ConfigurationRecorderIntegrationTest.java | 7 +++-- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/compatibility-tests/sdk-test-python/tests/test_config.py b/compatibility-tests/sdk-test-python/tests/test_config.py index d57e666b6b..e812f268e7 100644 --- a/compatibility-tests/sdk-test-python/tests/test_config.py +++ b/compatibility-tests/sdk-test-python/tests/test_config.py @@ -215,8 +215,9 @@ class TestComplianceLoop: class TestRecorderChannelLifecycle: """Test configuration recorder and delivery channel lifecycle.""" - def test_recorder_and_channel_lifecycle(self, config_client): + def test_recorder_and_channel_lifecycle(self, config_client, unique_name): """Test recorder/channel setup, the guarded channel delete, and both deletes.""" + channel_name = f"channel-{unique_name}" config_client.put_configuration_recorder( ConfigurationRecorder={ "name": "default", @@ -237,16 +238,27 @@ class TestRecorderChannelLifecycle: assert status.get("lastStartTime") is None config_client.put_delivery_channel( - DeliveryChannel={"name": "default", "s3BucketName": "config-bucket"} + DeliveryChannel={"name": channel_name, "s3BucketName": "config-bucket"} ) + with pytest.raises(ClientError) as exc: + config_client.describe_delivery_channels(DeliveryChannelNames=["missing-channel"]) + assert exc.value.response["Error"]["Code"] == "NoSuchDeliveryChannelException" + assert exc.value.response["Error"]["Message"] == ( + "Cannot find delivery channel with specified name 'missing-channel'." + ) + config_client.start_configuration_recorder(ConfigurationRecorderName="default") with pytest.raises(ClientError) as exc: - config_client.delete_delivery_channel(DeliveryChannelName="default") + config_client.delete_delivery_channel(DeliveryChannelName=channel_name) assert exc.value.response["Error"]["Code"] == "LastDeliveryChannelDeleteFailedException" + assert exc.value.response["Error"]["Message"] == ( + f"Failed to delete last specified delivery channel with name '{channel_name}', " + "because there is a running configuration recorder." + ) config_client.stop_configuration_recorder(ConfigurationRecorderName="default") - config_client.delete_delivery_channel(DeliveryChannelName="default") + config_client.delete_delivery_channel(DeliveryChannelName=channel_name) stopped = config_client.describe_configuration_recorder_status()[ "ConfigurationRecordersStatus" @@ -258,9 +270,16 @@ class TestRecorderChannelLifecycle: "ConfigurationRecordersStatus" ][0] == stopped + missing_message = f"Cannot find delivery channel with specified name '{channel_name}'." with pytest.raises(ClientError) as exc: - config_client.delete_delivery_channel(DeliveryChannelName="default") + config_client.describe_delivery_channels(DeliveryChannelNames=[channel_name]) assert exc.value.response["Error"]["Code"] == "NoSuchDeliveryChannelException" + assert exc.value.response["Error"]["Message"] == missing_message + + with pytest.raises(ClientError) as exc: + config_client.delete_delivery_channel(DeliveryChannelName=channel_name) + assert exc.value.response["Error"]["Code"] == "NoSuchDeliveryChannelException" + assert exc.value.response["Error"]["Message"] == missing_message finally: config_client.delete_configuration_recorder(ConfigurationRecorderName="default") diff --git a/src/main/java/io/floci/aws/services/configservice/AwsConfigService.java b/src/main/java/io/floci/aws/services/configservice/AwsConfigService.java index 3a7eb8d660..a5a2a684d8 100644 --- a/src/main/java/io/floci/aws/services/configservice/AwsConfigService.java +++ b/src/main/java/io/floci/aws/services/configservice/AwsConfigService.java @@ -749,40 +749,36 @@ public class AwsConfigService { public List describeDeliveryChannels(String region, List names) { DeliveryChannel channel = deliveryChannels.get(region); - if (channel == null) { - if (names != null && !names.isEmpty()) { - throw new AwsException("NoSuchDeliveryChannelException", - "Cannot find delivery channel with the specified name.", 400); - } - return Collections.emptyList(); - } - if (names != null && !names.isEmpty()) { + if (names != null) { for (String name : names) { - if (!name.equals(channel.name())) { - throw new AwsException("NoSuchDeliveryChannelException", - "Cannot find delivery channel with the specified name.", 400); + if (channel == null || !name.equals(channel.name())) { + throw noSuchDeliveryChannel(name); } } } - return List.of(channel); + return channel == null ? List.of() : List.of(channel); } public void deleteDeliveryChannel(String region, String name) { synchronized (lockFor(recorderLockKey(region))) { DeliveryChannel channel = deliveryChannels.get(region); if (channel == null || !channel.name().equals(name)) { - throw new AwsException("NoSuchDeliveryChannelException", - "Cannot find delivery channel with the specified name.", 400); + throw noSuchDeliveryChannel(name); } if (recorderRunning.getOrDefault(runtimeKey(region), false)) { throw new AwsException("LastDeliveryChannelDeleteFailedException", - "You cannot delete the delivery channel you specified because the customer managed " - + "configuration recorder is running.", 400); + "Failed to delete last specified delivery channel with name '" + name + + "', because there is a running configuration recorder.", 400); } deliveryChannels.remove(region); } } + private static AwsException noSuchDeliveryChannel(String name) { + return new AwsException("NoSuchDeliveryChannelException", + "Cannot find delivery channel with specified name '" + name + "'.", 400); + } + // --- Retention Configuration --- public RetentionConfiguration putRetentionConfiguration(String region, Integer retentionPeriodInDays) { diff --git a/src/test/java/io/floci/aws/services/configservice/ConfigurationRecorderIntegrationTest.java b/src/test/java/io/floci/aws/services/configservice/ConfigurationRecorderIntegrationTest.java index 82f4557518..aa4cffebc2 100644 --- a/src/test/java/io/floci/aws/services/configservice/ConfigurationRecorderIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/configservice/ConfigurationRecorderIntegrationTest.java @@ -271,7 +271,9 @@ class ConfigurationRecorderIntegrationTest { .post("/") .then() .statusCode(400) - .body("__type", equalTo("LastDeliveryChannelDeleteFailedException")); + .body("__type", equalTo("LastDeliveryChannelDeleteFailedException")) + .body("message", equalTo("Failed to delete last specified delivery channel with name 'default', " + + "because there is a running configuration recorder.")); } @Test @@ -313,7 +315,8 @@ class ConfigurationRecorderIntegrationTest { .post("/") .then() .statusCode(400) - .body("__type", equalTo("NoSuchDeliveryChannelException")); + .body("__type", equalTo("NoSuchDeliveryChannelException")) + .body("message", equalTo("Cannot find delivery channel with specified name 'default'.")); } @Test