Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 0fc8d0b

Browse files
committed
services/logs: Support ListLogGroups
This operation was flagged as missing in parity tests.
1 parent 1002e58 commit 0fc8d0b

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
InputLogEvents,
2323
InvalidParameterException,
2424
KmsKeyId,
25+
ListLogGroupsRequest,
26+
ListLogGroupsResponse,
2527
ListTagsForResourceResponse,
2628
ListTagsLogGroupResponse,
2729
LogGroupClass,
@@ -138,6 +140,21 @@ def describe_log_streams(
138140

139141
return moto.call_moto_with_request(context, request_copy)
140142

143+
@handler("ListLogGroups", expand=False)
144+
def list_log_groups(
145+
self, context: RequestContext, request: ListLogGroupsRequest
146+
) -> ListLogGroupsResponse:
147+
pattern: str | None = request.get("logGroupNamePattern")
148+
region_backend: LogsBackend = get_moto_logs_backend(context.account_id, context.region)
149+
copy_groups = copy.deepcopy(region_backend.groups)
150+
groups = [
151+
group.to_describe_dict()
152+
for name, group in copy_groups.items()
153+
if not pattern or pattern in name
154+
]
155+
groups = sorted(groups, key=lambda x: x["logGroupName"])
156+
return ListLogGroupsResponse(logGroups=groups)
157+
141158
def create_log_group(
142159
self,
143160
context: RequestContext,

tests/aws/services/logs/test_logs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ def test_create_and_delete_log_stream(self, logs_log_group, aws_client, region_n
204204
)
205205
snapshot.match("error-describe-logs-group", ctx.value.response)
206206

207+
response = aws_client.logs.list_log_groups(logGroupNamePattern="no-such-group")
208+
snapshot.match("list-log-groups-pattern-no-match", response)
209+
response = aws_client.logs.list_log_groups(
210+
logGroupNamePattern=logs_log_group.split("-")[-1]
211+
)
212+
snapshot.match("list-log-groups-pattern-match", response)
213+
207214
aws_client.logs.create_log_stream(logGroupName=logs_log_group, logStreamName=test_name)
208215
log_streams_between = aws_client.logs.describe_log_streams(logGroupName=logs_log_group).get(
209216
"logStreams", []

tests/aws/services/logs/test_logs.snapshot.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@
140140
}
141141
},
142142
"tests/aws/services/logs/test_logs.py::TestCloudWatchLogs::test_create_and_delete_log_stream": {
143-
"recorded-date": "06-04-2023, 11:42:42",
143+
"recorded-date": "04-11-2025, 18:45:08",
144144
"recorded-content": {
145145
"describe-log-groups-prefix": {
146146
"logGroups": [
147147
{
148148
"arn": "arn:<partition>:logs:<region>:111111111111:log-group:<log-group-name:1>:*",
149149
"creationTime": "timestamp",
150+
"logGroupArn": "arn:<partition>:logs:<region>:111111111111:log-group:<log-group-name:1>",
151+
"logGroupClass": "STANDARD",
150152
"logGroupName": "<log-group-name:1>",
151153
"metricFilterCount": 0,
152154
"storedBytes": 0
@@ -181,6 +183,27 @@
181183
"HTTPStatusCode": 400
182184
}
183185
},
186+
"list-log-groups-pattern-no-match": {
187+
"logGroups": [],
188+
"ResponseMetadata": {
189+
"HTTPHeaders": {},
190+
"HTTPStatusCode": 200
191+
}
192+
},
193+
"list-log-groups-pattern-match": {
194+
"logGroups": [
195+
{
196+
"logGroupArn": "arn:<partition>:logs:<region>:111111111111:log-group:<log-group-name:1>",
197+
"logGroupClass": "STANDARD",
198+
"logGroupName": "<log-group-name:1>"
199+
}
200+
],
201+
"nextToken": "<next_token>",
202+
"ResponseMetadata": {
203+
"HTTPHeaders": {},
204+
"HTTPStatusCode": 200
205+
}
206+
},
184207
"logs_log_group": [
185208
{
186209
"logStreamName": "<log-stream-name:1>",

tests/aws/services/logs/test_logs.validation.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
"last_validated_date": "2024-05-24T13:57:11+00:00"
44
},
55
"tests/aws/services/logs/test_logs.py::TestCloudWatchLogs::test_create_and_delete_log_stream": {
6-
"last_validated_date": "2023-04-06T09:42:42+00:00"
6+
"last_validated_date": "2025-11-04T18:45:08+00:00",
7+
"durations_in_seconds": {
8+
"setup": 2.02,
9+
"call": 2.98,
10+
"teardown": 0.16,
11+
"total": 5.16
12+
}
713
},
814
"tests/aws/services/logs/test_logs.py::TestCloudWatchLogs::test_filter_log_events_response_header": {
915
"last_validated_date": "2024-05-24T13:58:30+00:00"

0 commit comments

Comments
 (0)