AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或DescribeLogGroups
一起使用 CLI
以下代码示例演示如何使用 DescribeLogGroups
。
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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); } }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 DescribeLogGroups” 中的。
-
- CLI
-
- AWS CLI
-
以下命令将描述名为
my-logs
的日志组:aws logs describe-log-groups --log-group-name-prefix
my-logs
输出:
{ "logGroups": [ { "storedBytes": 0, "metricFilterCount": 0, "creationTime": 1433189500783, "logGroupName": "my-logs", "retentionInDays": 5, "arn": "arn:aws:logs:us-west-2:0123456789012:log-group:my-logs:*" } ] }
-
有关API详细信息,请参阅 “DescribeLogGroups AWS CLI
命令参考”。
-
- JavaScript
-
- SDK对于 JavaScript (v3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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; };
-
有关API详细信息,请参阅 “AWS SDK for JavaScript API参考 DescribeLogGroups” 中的。
-
DescribeExportTasks
DescribeSubscriptionFilters