Use DescribeLogGroups
with an Amazon SDK or CLI
The following code examples show how to use DescribeLogGroups
.
- .NET
-
- Amazon SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. using System; using System.Threading.Tasks; using Amazon.CloudWatchLogs; using Amazon.CloudWatchLogs.Model; /// <summary> /// Retrieves information about existing Amazon CloudWatch Logs log groups /// and displays the information on the console. /// </summary> public class DescribeLogGroups { public static async Task Main() { // Creates a CloudWatch Logs client using the default // user. If you need to work with resources in another // AWS Region than the one defined for the default user, // pass the AWS Region as a parameter to the client constructor. var client = new AmazonCloudWatchLogsClient(); bool done = false; string newToken = null; var request = new DescribeLogGroupsRequest { Limit = 5, }; DescribeLogGroupsResponse response; do { if (newToken is not null) { request.NextToken = newToken; } response = await client.DescribeLogGroupsAsync(request); response.LogGroups.ForEach(lg => { Console.WriteLine($"{lg.LogGroupName} is associated with the key: {lg.KmsKeyId}."); Console.WriteLine($"Created on: {lg.CreationTime.Date.Date}"); Console.WriteLine($"Date for this group will be stored for: {lg.RetentionInDays} days.\n"); }); if (response.NextToken is null) { done = true; } else { newToken = response.NextToken; } } while (!done); } }
-
For API details, see DescribeLogGroups in Amazon SDK for .NET API Reference.
-
- CLI
-
- Amazon CLI
-
The following command describes a log group named
my-logs
:aws logs describe-log-groups --log-group-name-prefix
my-logs
Output:
{ "logGroups": [ { "storedBytes": 0, "metricFilterCount": 0, "creationTime": 1433189500783, "logGroupName": "my-logs", "retentionInDays": 5, "arn": "arn:aws:logs:us-west-2:0123456789012:log-group:my-logs:*" } ] }
-
For API details, see DescribeLogGroups
in Amazon CLI Command Reference.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. import { paginateDescribeLogGroups, CloudWatchLogsClient, } from "@aws-sdk/client-cloudwatch-logs"; const client = new CloudWatchLogsClient({}); export const main = async () => { const paginatedLogGroups = paginateDescribeLogGroups({ client }, {}); const logGroups = []; for await (const page of paginatedLogGroups) { if (page.logGroups && page.logGroups.every((lg) => !!lg)) { logGroups.push(...page.logGroups); } } console.log(logGroups); return logGroups; };
-
For API details, see DescribeLogGroups in Amazon SDK for JavaScript API Reference.
-
For a complete list of Amazon SDK developer guides and code examples, see Using CloudWatch Logs with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.