DescribeLogGroups - Amazon CloudWatch Logs

DescribeLogGroups

Lists the specified log groups. You can list all your log groups or filter the results by prefix. The results are ASCII-sorted by log group name.

CloudWatch Logs doesn’t support IAM policies that control access to the DescribeLogGroups action by using the aws:ResourceTag/key-name condition key. Other CloudWatch Logs actions do support the use of the aws:ResourceTag/key-name condition key to control access. For more information about using tags to control access, see Controlling access to Amazon Web Services resources using tags.

If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account and view data from the linked source accounts. For more information, see CloudWatch cross-account observability.

Request Syntax

{ "accountIdentifiers": [ "string" ], "includeLinkedAccounts": boolean, "limit": number, "logGroupNamePattern": "string", "logGroupNamePrefix": "string", "nextToken": "string" }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

accountIdentifiers

When includeLinkedAccounts is set to True, use this parameter to specify the list of accounts to search. You can specify as many as 20 account IDs in the array.

Type: Array of strings

Array Members: Minimum number of 0 items. Maximum number of 20 items.

Length Constraints: Fixed length of 12.

Pattern: ^\d{12}$

Required: No

includeLinkedAccounts

If you are using a monitoring account, set this to True to have the operation return log groups in the accounts listed in accountIdentifiers.

If this parameter is set to true and accountIdentifiers contains a null value, the operation returns all log groups in the monitoring account and all log groups in all source accounts that are linked to the monitoring account.

Type: Boolean

Required: No

limit

The maximum number of items returned. If you don't specify a value, the default is up to 50 items.

Type: Integer

Valid Range: Minimum value of 1. Maximum value of 50.

Required: No

logGroupNamePattern

If you specify a string for this parameter, the operation returns only log groups that have names that match the string based on a case-sensitive substring search. For example, if you specify Foo, log groups named FooBar, aws/Foo, and GroupFoo would match, but foo, F/o/o and Froo would not match.

If you specify logGroupNamePattern in your request, then metricFilterCount, retentionInDays, and storedBytes are not included in the response.

Note

logGroupNamePattern and logGroupNamePrefix are mutually exclusive. Only one of these parameters can be passed.

Type: String

Length Constraints: Minimum length of 0. Maximum length of 512.

Pattern: [\.\-_/#A-Za-z0-9]*

Required: No

logGroupNamePrefix

The prefix to match.

Note

logGroupNamePrefix and logGroupNamePattern are mutually exclusive. Only one of these parameters can be passed.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 512.

Pattern: [\.\-_/#A-Za-z0-9]+

Required: No

nextToken

The token for the next set of items to return. (You received this token from a previous call.)

Type: String

Length Constraints: Minimum length of 1.

Required: No

Response Syntax

{ "logGroups": [ { "arn": "string", "creationTime": number, "dataProtectionStatus": "string", "kmsKeyId": "string", "logGroupName": "string", "metricFilterCount": number, "retentionInDays": number, "storedBytes": number } ], "nextToken": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

logGroups

The log groups.

If the retentionInDays value is not included for a log group, then that log group's events do not expire.

Type: Array of LogGroup objects

nextToken

The token for the next set of items to return. The token expires after 24 hours.

Type: String

Length Constraints: Minimum length of 1.

Errors

For information about the errors that are common to all actions, see Common Errors.

InvalidParameterException

A parameter is specified incorrectly.

HTTP Status Code: 400

ServiceUnavailableException

The service cannot complete the request.

HTTP Status Code: 500

Examples

To list all log groups

The following example lists all your log groups.

Sample Request

POST / HTTP/1.1 Host: logs.<region>.<domain> X-Amz-Date: <DATE> Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=content-type;date;host;user-agent;x-amz-date;x-amz-target;x-amzn-requestid, Signature=<Signature> User-Agent: <UserAgentString> Accept: application/json Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Connection: Keep-Alive X-Amz-Target: Logs_20140328.DescribeLogGroups

Sample Response

HTTP/1.1 200 OK x-amzn-RequestId: <RequestId> Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Date: <Date> { "logGroups": [ { "storageBytes": 1048576, "arn": "arn:aws:logs:us-east-1:123456789012:log-group:my-log-group-1:*", "creationTime": 1393545600000, "logGroupName": "my-log-group-1", "metricFilterCount": 0, "retentionInDays": 14, "kmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/abcd1234-a123-456a-a12b-a123b4cd56ef" }, { "storageBytes": 5242880, "arn": "arn:aws:logs:us-east-1:123456789012:log-group:my-log-group-2:*", "creationTime": 1396224000000, "logGroupName": "my-log-group-2", "metricFilterCount": 0, "retentionInDays": 30 } ] }

To list all of the log groups in a monitoring account and all linked source accounts that have logGroup in their name

The following example lists all of the log groups in a monitoring account and all linked source accounts that have logGroup in their name.

Sample Request

{ "includeLinkedAccounts" : "true", "logGroupNamePattern": "logGroup" }

Sample Response

{ "logGroups": [ { "arn": "arn:aws:logs:us-east-1:123456789012:log-group:monitoring-logGroup-1234:*", "creationTime": 1393545600000, "logGroupName": "monitoring-logGroup-1234" }, { "arn": "arn:aws:logs:us-east-1:012345678901:log-group:source-loggroup-5678:*", "creationTime": 1396224000000, "logGroupName": "source-loggroup-5678" } ] }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: