From b670962c5ed2d5067626b9d020d15964e7e2fbcd Mon Sep 17 00:00:00 2001 From: Austin Hendrix Date: Wed, 2 Jun 2021 10:27:23 -0500 Subject: [PATCH] SSM Parameter Store Error Message When Requesting Invalid Version (#3977) * Implement correct error when requesting specific version of a parameter which exists but does not have this version * removing trailing whitespace causing lint failure * Adding unit tests and fixing linting for new error handling * Fixing small bug in response message * Revert change in get_parameters as versioning is not currently implemented in this method. Will fix as a separate PR --- moto/ssm/models.py | 7 ++++++- tests/test_ssm/test_ssm_boto3.py | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/moto/ssm/models.py b/moto/ssm/models.py index 74f60e58a..fe6c64ee8 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -1217,7 +1217,12 @@ class SimpleSystemManagerBackend(BaseBackend): ) if len(result) > 0: return result[-1] - + elif len(parameters) > 0: + raise ParameterVersionNotFound( + "Systems Manager could not find version %s of %s. " + "Verify the version and try again." + % (version_or_label, name_prefix) + ) result = list( filter(lambda x: version_or_label in x.labels, parameters) ) diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index 3301ed32c..ddf033cfc 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -465,8 +465,15 @@ def test_get_parameter_with_version_and_labels(): with pytest.raises(ClientError) as ex: client.get_parameter(Name="test-2:2", WithDecryption=False) + ex.value.response["Error"]["Code"].should.equal("ParameterVersionNotFound") + ex.value.response["Error"]["Message"].should.equal( + "Systems Manager could not find version 2 of test-2. Verify the version and try again." + ) + + with pytest.raises(ClientError) as ex: + client.get_parameter(Name="test-3:2", WithDecryption=False) ex.value.response["Error"]["Code"].should.equal("ParameterNotFound") - ex.value.response["Error"]["Message"].should.equal("Parameter test-2:2 not found.") + ex.value.response["Error"]["Message"].should.equal("Parameter test-3:2 not found.") @mock_ssm