Reputation: 9387
How to I list all the log groups in Cloudwatch using Boto3. When I try the below syntax. I get error.
client = boto3.client('logs')
response = client.describe_log_groups(limit=51)
validation error detected: Value '51' at 'limit' failed to satisfy constraint: Member must have value less than or equal to 50
Based on documentation we could go above 50
limit (integer) -- The maximum number of items returned. If you don't specify a value, the default is up to 50 items.
Upvotes: 2
Views: 6013
Reputation: 146
The paginate()
function includes a build_full_result()
method, eliminating the for page in paginator.paginate():
paginator = logs_client.get_paginator('describe_log_groups')
log_groups = paginator.paginate().build_full_result()
for group in page['logGroups']:
print(group)
Upvotes: 0
Reputation: 4486
When in doubt, always go to the API documentation, which says the following:
Valid Range: Minimum value of 1. Maximum value of 50.
To solve your problem, you need to use a paginator:
paginator = logs_client.get_paginator('describe_log_groups')
for page in paginator.paginate():
for group in page['logGroups']:
print(group)
Upvotes: 5