Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSM: PutParameter requires Type for parameter updates #6416

Closed
joshuapmorgan opened this issue Jun 16, 2023 · 8 comments · Fixed by #6432 or #6436
Closed

SSM: PutParameter requires Type for parameter updates #6416

joshuapmorgan opened this issue Jun 16, 2023 · 8 comments · Fixed by #6432 or #6436
Labels

Comments

@joshuapmorgan
Copy link

moto version: 4.1.11 using Python mocks (boto3 1.22.12/botocore 1.25.12)

Per AWS documentation, specifiying a Type in PutParameter request is not required when updating a parameter. However, when using moto, PutParameter Type field is required even if the parameter already exists and is intended to be updated.

import os

import boto3
import moto

os.environ = {
    "AWS_DEFAULT_REGION": "us-east-1",
    "AWS_ACCESS_KEY_ID": "testing",
    "AWS_SECRET_ACCESS_KEY": "testing",
    "AWS_SESSION_TOKEN": "testing",
}

with moto.mock_ssm():
    ssm_client = boto3.client("ssm")
    ssm_client.put_parameter(
        Description="Description",
        Name="Name",
        Type="String",
        Value="Value",
    )
    ssm_client.put_parameter(
        Name="Name",
        Overwrite=True,
        Value="UpdatedValue",
    )

In the code above, the second put_parameter call fails unexpectedly with the following exception.

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutParameter operation: 1 validation error detected: Value 'None' at 'type' failed to satisfy constraint: Member must satisfy enum value set: [SecureString, StringList, String]

When I tested this under moto 3.1.8, the Type parameter is not required for put_parameter. However, because the second call to put_parameter lacks a Type parameter, subsequent calls to describe_parameters results in a response that lacks a Type for parameters. The expected result in this case is that the parameter maintains the Type supplied in the initial put_parameter call that created the parameter.

@bblommers
Copy link
Collaborator

Hi @joshuapmorgan, welcome to Moto! Thanks for raising this and for providing the repro - marking it as a bug.

@bblommers bblommers added the bug label Jun 18, 2023
@rafcio19
Copy link
Contributor

@bblommers I can take a look

@bblommers
Copy link
Collaborator

@rafcio19 I'm opening this back up, as the PR only solved one problem - the validation issue.
This is still outstanding:

The expected result in this case is that the parameter maintains the Type supplied in the initial put_parameter call that created the parameter.

@bfbenf
Copy link
Contributor

bfbenf commented Jul 4, 2023

@rafcio19

I have installed the latest release (moto-4.1.13.dev24) and I am still getting an error when not including Type which is optional according to the SSM Docs.

Error: botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutParameter operation: A parameter type is required when you create a parameter.

@rafcio19
Copy link
Contributor

rafcio19 commented Jul 5, 2023

@bfbenf the OP's example is working like expected for me, from our tests:

@mock_ssm
def test_update_parameter():
    # Setup
    client = boto3.client("ssm", "us-east-1")
    param_name = "test_param"
    param_type = "String"
    updated_value = "UpdatedValue"
    client.put_parameter(
        Description="Description",
        Name=param_name,
        Type=param_type,
        Value="Value",
    )

    # Execute
    response = client.put_parameter(
        Name=param_name,
        Overwrite=True,
        Value=updated_value,
    )
    new_param = client.get_parameter(Name=param_name)

    # Verify
    assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
    assert new_param["Parameter"]["Type"] == param_type
    assert new_param["Parameter"]["Value"] == updated_value

Can you try this test or share a code sample that's failing?

@bfbenf
Copy link
Contributor

bfbenf commented Jul 12, 2023

@rafcio19

Sorry, it took a while to get back to you. When I run the following, I get this error.

According to https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm/client/put_parameter.html Type is an optional param

import unittest

import boto3
from moto import mock_ssm


@mock_ssm
class TestExample(unittest.TestCase):
    def test_update_parameter(self):
        # Setup
        client = boto3.client("ssm")
        client.put_parameter(
            Name="test/with/type",
            Type="String",
            Value="Value",
        )

        # Execute
        client.put_parameter(
            Name="test/without/type",
            Value="value",
        )
E
======================================================================
ERROR: test_update_parameter (tests.test_moto.TestExample)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/bfbenf/dev/brewconf-wrapper/src/.venv/lib/python3.10/site-packages/moto/core/models.py", line 128, in wrapper
    result = func(*args, **kwargs)
  File "/Users/bfbenf/dev/tests/test_moto.py", line 19, in test_update_parameter
    client.put_parameter(
  File "/Users/bfbenf/dev//src/.venv/lib/python3.10/site-packages/botocore/client.py", line 534, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/bfbenf/dev/src/.venv/lib/python3.10/site-packages/botocore/client.py", line 976, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutParameter operation: A parameter type is required when you create a parameter.

----------------------------------------------------------------------
Ran 1 test in 0.500s

FAILED (errors=1)

@rafcio19
Copy link
Contributor

@bfbenf that's an expected error, Type is required when creating a new SSM parameter and you are creating a new parameter test/without/type:

Type (string) –

The type of parameter that you want to add to the system.
...
Warning
Specifying a parameter type isn’t required when updating a parameter. You must specify a parameter type when creating a parameter.

See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm/client/put_parameter.html

@bfbenf
Copy link
Contributor

bfbenf commented Jul 12, 2023

@rafcio19 You mean that big yellow warning box that I didn't read .... whoops 😅

Apologies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants