Skip to content

Commit c5556b3

Browse files
committed
Fix SSM parameter handling with paths and queries by ARN
1 parent ec18ec9 commit c5556b3

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed

localstack-core/localstack/services/ssm/provider.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,12 @@ def _has_secrets(names: ParameterNameList) -> Boolean:
352352
@staticmethod
353353
def _normalize_name(param_name: ParameterName, validate=False) -> ParameterName:
354354
if is_arn(param_name):
355-
return extract_resource_from_arn(param_name).split("/")[-1]
355+
resource_name = extract_resource_from_arn(param_name).replace("parameter/", "")
356+
# if the parameter name is only the root path we want to look up without the leading slash.
357+
# Otherwise, we add the leading slash
358+
if "/" in resource_name:
359+
resource_name = f"/{resource_name}"
360+
return resource_name
356361

357362
if validate:
358363
if "//" in param_name or ("/" in param_name and not param_name.startswith("/")):

tests/aws/services/ssm/test_ssm.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,32 @@ def assert_message():
234234

235235
# clean up
236236
clean_up(rule_name=rule_name, target_ids=target_id)
237+
238+
@markers.aws.validated
239+
@markers.snapshot.skip_snapshot_verify(paths=["$..Tier"])
240+
def test_parameters_with_path(self, create_parameter, aws_client, snapshot):
241+
snapshot.add_transformer(snapshot.transform.key_value("Name"))
242+
param_name = f"/test/param-{short_uid()}"
243+
put_parameter_response = create_parameter(
244+
Name=param_name,
245+
Description="test",
246+
Value="123",
247+
Type="String",
248+
)
249+
snapshot.match("put-parameter-response", put_parameter_response)
250+
251+
get_parameter_response = aws_client.ssm.get_parameter(Name=param_name)
252+
snapshot.match("get-parameter-response", get_parameter_response)
253+
254+
get_parameter_by_arn_response = aws_client.ssm.get_parameter(
255+
Name=get_parameter_response["Parameter"]["ARN"]
256+
)
257+
snapshot.match("get-parameter-by-arn-response", get_parameter_by_arn_response)
258+
259+
get_parameters_response = aws_client.ssm.get_parameters(Names=[param_name])
260+
snapshot.match("get-parameters-response", get_parameters_response)
261+
262+
get_parameters_by_arn_response = aws_client.ssm.get_parameters(
263+
Names=[get_parameter_response["Parameter"]["ARN"]]
264+
)
265+
snapshot.match("get-parameters-by-arn-response", get_parameters_by_arn_response)

tests/aws/services/ssm/test_ssm.snapshot.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,84 @@
1212
"Version": 1
1313
}
1414
}
15+
},
16+
"tests/aws/services/ssm/test_ssm.py::TestSSM::test_parameters_with_path": {
17+
"recorded-date": "08-01-2025, 17:04:53",
18+
"recorded-content": {
19+
"put-parameter-response": {
20+
"Tier": "Standard",
21+
"Version": 1,
22+
"ResponseMetadata": {
23+
"HTTPHeaders": {},
24+
"HTTPStatusCode": 200
25+
}
26+
},
27+
"get-parameter-response": {
28+
"Parameter": {
29+
"ARN": "arn:<partition>:ssm:<region>:111111111111:parameter<name:1>",
30+
"DataType": "text",
31+
"LastModifiedDate": "<datetime>",
32+
"Name": "<name:1>",
33+
"Type": "String",
34+
"Value": "123",
35+
"Version": 1
36+
},
37+
"ResponseMetadata": {
38+
"HTTPHeaders": {},
39+
"HTTPStatusCode": 200
40+
}
41+
},
42+
"get-parameter-by-arn-response": {
43+
"Parameter": {
44+
"ARN": "arn:<partition>:ssm:<region>:111111111111:parameter<name:1>",
45+
"DataType": "text",
46+
"LastModifiedDate": "<datetime>",
47+
"Name": "<name:1>",
48+
"Type": "String",
49+
"Value": "123",
50+
"Version": 1
51+
},
52+
"ResponseMetadata": {
53+
"HTTPHeaders": {},
54+
"HTTPStatusCode": 200
55+
}
56+
},
57+
"get-parameters-response": {
58+
"InvalidParameters": [],
59+
"Parameters": [
60+
{
61+
"ARN": "arn:<partition>:ssm:<region>:111111111111:parameter<name:1>",
62+
"DataType": "text",
63+
"LastModifiedDate": "<datetime>",
64+
"Name": "<name:1>",
65+
"Type": "String",
66+
"Value": "123",
67+
"Version": 1
68+
}
69+
],
70+
"ResponseMetadata": {
71+
"HTTPHeaders": {},
72+
"HTTPStatusCode": 200
73+
}
74+
},
75+
"get-parameters-by-arn-response": {
76+
"InvalidParameters": [],
77+
"Parameters": [
78+
{
79+
"ARN": "arn:<partition>:ssm:<region>:111111111111:parameter<name:1>",
80+
"DataType": "text",
81+
"LastModifiedDate": "<datetime>",
82+
"Name": "<name:1>",
83+
"Type": "String",
84+
"Value": "123",
85+
"Version": 1
86+
}
87+
],
88+
"ResponseMetadata": {
89+
"HTTPHeaders": {},
90+
"HTTPStatusCode": 200
91+
}
92+
}
93+
}
1594
}
1695
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"tests/aws/services/ssm/test_ssm.py::TestSSM::test_get_parameter_by_arn": {
33
"last_validated_date": "2024-07-16T17:17:40+00:00"
4+
},
5+
"tests/aws/services/ssm/test_ssm.py::TestSSM::test_parameters_with_path": {
6+
"last_validated_date": "2025-01-08T17:04:53+00:00"
47
}
58
}

0 commit comments

Comments
 (0)