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.
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)