diff --git a/moto/ssm/models.py b/moto/ssm/models.py index 63cb3c8ba..bbb84ad91 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -52,6 +52,16 @@ class SimpleSystemManagerBackend(BaseBackend): except KeyError: pass + def delete_parameters(self, names): + result = [] + for name in names: + try: + del self._parameters[name] + result.append(name) + except KeyError: + pass + return result + def get_all_parameters(self): result = [] for k, _ in self._parameters.items(): diff --git a/moto/ssm/responses.py b/moto/ssm/responses.py index 1fa1a81b2..73c29484a 100644 --- a/moto/ssm/responses.py +++ b/moto/ssm/responses.py @@ -26,6 +26,22 @@ class SimpleSystemManagerResponse(BaseResponse): self.ssm_backend.delete_parameter(name) return json.dumps({}) + def delete_parameters(self): + names = self._get_param('Names') + result = self.ssm_backend.delete_parameters(names) + + response = { + 'DeletedParameters': [], + 'InvalidParameters': [] + } + + for name in names: + if name in result: + response['DeletedParameters'].append(name) + else: + response['InvalidParameters'].append(name) + return json.dumps(response) + def get_parameters(self): names = self._get_param('Names') with_decryption = self._get_param('WithDecryption') diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index 418c58708..38e266445 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -24,6 +24,25 @@ def test_delete_parameter(): response = client.get_parameters(Names=['test']) len(response['Parameters']).should.equal(0) +@mock_ssm +def test_delete_parameters(): + client = boto3.client('ssm', region_name='us-east-1') + + client.put_parameter( + Name='test', + Description='A test parameter', + Value='value', + Type='String') + + response = client.get_parameters(Names=['test']) + len(response['Parameters']).should.equal(1) + + result = client.delete_parameters(Names=['test', 'invalid']) + len(result['DeletedParameters']).should.equal(1) + len(result['InvalidParameters']).should.equal(1) + + response = client.get_parameters(Names=['test']) + len(response['Parameters']).should.equal(0) @mock_ssm def test_put_parameter():