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

Commit f17706f

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

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ 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()
208+
snapshot.match("list-log-groups", response)
209+
210+
response = aws_client.logs.list_log_groups(logGroupNamePattern="no-such-group")
211+
snapshot.match("list-log-groups-pattern-no-match", response)
212+
response = aws_client.logs.list_log_groups(
213+
logGroupNamePattern=logs_log_group.split("-")[-1]
214+
)
215+
snapshot.match("list-log-groups-pattern-match", response)
216+
207217
aws_client.logs.create_log_stream(logGroupName=logs_log_group, logStreamName=test_name)
208218
log_streams_between = aws_client.logs.describe_log_streams(logGroupName=logs_log_group).get(
209219
"logStreams", []

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

Lines changed: 38 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,41 @@
181183
"HTTPStatusCode": 400
182184
}
183185
},
186+
"list-log-groups": {
187+
"logGroups": [
188+
{
189+
"logGroupArn": "arn:<partition>:logs:<region>:111111111111:log-group:<log-group-name:1>",
190+
"logGroupClass": "STANDARD",
191+
"logGroupName": "<log-group-name:1>"
192+
}
193+
],
194+
"nextToken": "<next_token>",
195+
"ResponseMetadata": {
196+
"HTTPHeaders": {},
197+
"HTTPStatusCode": 200
198+
}
199+
},
200+
"list-log-groups-pattern-no-match": {
201+
"logGroups": [],
202+
"ResponseMetadata": {
203+
"HTTPHeaders": {},
204+
"HTTPStatusCode": 200
205+
}
206+
},
207+
"list-log-groups-pattern-match": {
208+
"logGroups": [
209+
{
210+
"logGroupArn": "arn:<partition>:logs:<region>:111111111111:log-group:<log-group-name:1>",
211+
"logGroupClass": "STANDARD",
212+
"logGroupName": "<log-group-name:1>"
213+
}
214+
],
215+
"nextToken": "<next_token>",
216+
"ResponseMetadata": {
217+
"HTTPHeaders": {},
218+
"HTTPStatusCode": 200
219+
}
220+
},
184221
"logs_log_group": [
185222
{
186223
"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)