Table of Contents
CloudWatchLogs.Client¶A low-level client representing Amazon CloudWatch Logs:
client = session.create_client('logs')
These are the available methods:
can_paginate()cancel_export_task()create_export_task()create_log_group()create_log_stream()delete_destination()delete_log_group()delete_log_stream()delete_metric_filter()delete_retention_policy()delete_subscription_filter()describe_destinations()describe_export_tasks()describe_log_groups()describe_log_streams()describe_metric_filters()describe_subscription_filters()filter_log_events()generate_presigned_url()get_log_events()get_paginator()get_waiter()list_tags_log_group()put_destination()put_destination_policy()put_log_events()put_metric_filter()put_retention_policy()put_subscription_filter()tag_log_group()test_metric_filter()untag_log_group()can_paginate(operation_name)¶Check if an operation can be paginated.
| Parameters: | operation_name (string) – The operation name. This is the same name
as the method name on the client. For example, if the
method name is create_foo, and you’d normally invoke the
operation as client.create_foo(**kwargs), if the
create_foo operation can be paginated, you can use the
call client.get_paginator("create_foo"). |
|---|---|
| Returns: | True if the operation can be paginated,
False otherwise. |
cancel_export_task(**kwargs)¶Cancels the specified export task.
The task must be in the PENDING or RUNNING state.
See also: AWS API Documentation
Request Syntax
response = client.cancel_export_task(
taskId='string'
)
| Parameters: | taskId (string) – [REQUIRED] The ID of the export task. |
|---|---|
| Returns: | None |
create_export_task(**kwargs)¶Creates an export task, which allows you to efficiently export data from a log group to an Amazon S3 bucket.
This is an asynchronous call. If all the required information is provided, this operation initiates an export task and responds with the ID of the task. After the task has started, you can use DescribeExportTasks to get the status of the export task. Each account can only have one active (RUNNING or PENDING ) export task at a time. To cancel an export task, use CancelExportTask .
You can export logs from multiple log groups or multiple time ranges to the same S3 bucket. To separate out log data for each export task, you can specify a prefix that will be used as the Amazon S3 key prefix for all exported objects.
See also: AWS API Documentation
Request Syntax
response = client.create_export_task(
taskName='string',
logGroupName='string',
logStreamNamePrefix='string',
fromTime=123,
to=123,
destination='string',
destinationPrefix='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'taskId': 'string'
}
Response Structure
|
create_log_group(**kwargs)¶Creates a log group with the specified name.
You can create up to 5000 log groups per account.
You must use the following guidelines when naming a log group:
See also: AWS API Documentation
Request Syntax
response = client.create_log_group(
logGroupName='string',
tags={
'string': 'string'
}
)
| Parameters: |
|
|---|---|
| Returns: | None |
create_log_stream(**kwargs)¶Creates a log stream for the specified log group.
There is no limit on the number of log streams that you can create for a log group.
You must use the following guidelines when naming a log stream:
See also: AWS API Documentation
Request Syntax
response = client.create_log_stream(
logGroupName='string',
logStreamName='string'
)
| Parameters: |
|
|---|---|
| Returns: | None |
delete_destination(**kwargs)¶Deletes the specified destination, and eventually disables all the subscription filters that publish to it. This operation does not delete the physical resource encapsulated by the destination.
See also: AWS API Documentation
Request Syntax
response = client.delete_destination(
destinationName='string'
)
| Parameters: | destinationName (string) – [REQUIRED] The name of the destination. |
|---|---|
| Returns: | None |
delete_log_group(**kwargs)¶Deletes the specified log group and permanently deletes all the archived log events associated with the log group.
See also: AWS API Documentation
Request Syntax
response = client.delete_log_group(
logGroupName='string'
)
| Parameters: | logGroupName (string) – [REQUIRED] The name of the log group. |
|---|---|
| Returns: | None |
delete_log_stream(**kwargs)¶Deletes the specified log stream and permanently deletes all the archived log events associated with the log stream.
See also: AWS API Documentation
Request Syntax
response = client.delete_log_stream(
logGroupName='string',
logStreamName='string'
)
| Parameters: |
|
|---|---|
| Returns: | None |
delete_metric_filter(**kwargs)¶Deletes the specified metric filter.
See also: AWS API Documentation
Request Syntax
response = client.delete_metric_filter(
logGroupName='string',
filterName='string'
)
| Parameters: |
|
|---|---|
| Returns: | None |
delete_retention_policy(**kwargs)¶Deletes the specified retention policy.
Log events do not expire if they belong to log groups without a retention policy.
See also: AWS API Documentation
Request Syntax
response = client.delete_retention_policy(
logGroupName='string'
)
| Parameters: | logGroupName (string) – [REQUIRED] The name of the log group. |
|---|---|
| Returns: | None |
delete_subscription_filter(**kwargs)¶Deletes the specified subscription filter.
See also: AWS API Documentation
Request Syntax
response = client.delete_subscription_filter(
logGroupName='string',
filterName='string'
)
| Parameters: |
|
|---|---|
| Returns: | None |
describe_destinations(**kwargs)¶Lists all your destinations. The results are ASCII-sorted by destination name.
See also: AWS API Documentation
Request Syntax
response = client.describe_destinations(
DestinationNamePrefix='string',
nextToken='string',
limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'destinations': [
{
'destinationName': 'string',
'targetArn': 'string',
'roleArn': 'string',
'accessPolicy': 'string',
'arn': 'string',
'creationTime': 123
},
],
'nextToken': 'string'
}
Response Structure
|
describe_export_tasks(**kwargs)¶Lists the specified export tasks. You can list all your export tasks or filter the results based on task ID or task status.
See also: AWS API Documentation
Request Syntax
response = client.describe_export_tasks(
taskId='string',
statusCode='CANCELLED'|'COMPLETED'|'FAILED'|'PENDING'|'PENDING_CANCEL'|'RUNNING',
nextToken='string',
limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'exportTasks': [
{
'taskId': 'string',
'taskName': 'string',
'logGroupName': 'string',
'from': 123,
'to': 123,
'destination': 'string',
'destinationPrefix': 'string',
'status': {
'code': 'CANCELLED'|'COMPLETED'|'FAILED'|'PENDING'|'PENDING_CANCEL'|'RUNNING',
'message': 'string'
},
'executionInfo': {
'creationTime': 123,
'completionTime': 123
}
},
],
'nextToken': 'string'
}
Response Structure
|
describe_log_groups(**kwargs)¶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.
See also: AWS API Documentation
Request Syntax
response = client.describe_log_groups(
logGroupNamePrefix='string',
nextToken='string',
limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'logGroups': [
{
'logGroupName': 'string',
'creationTime': 123,
'retentionInDays': 123,
'metricFilterCount': 123,
'arn': 'string',
'storedBytes': 123
},
],
'nextToken': 'string'
}
Response Structure
|
describe_log_streams(**kwargs)¶Lists the log streams for the specified log group. You can list all the log streams or filter the results by prefix. You can also control how the results are ordered.
This operation has a limit of five transactions per second, after which transactions are throttled.
See also: AWS API Documentation
Request Syntax
response = client.describe_log_streams(
logGroupName='string',
logStreamNamePrefix='string',
orderBy='LogStreamName'|'LastEventTime',
descending=True|False,
nextToken='string',
limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'logStreams': [
{
'logStreamName': 'string',
'creationTime': 123,
'firstEventTimestamp': 123,
'lastEventTimestamp': 123,
'lastIngestionTime': 123,
'uploadSequenceToken': 'string',
'arn': 'string',
'storedBytes': 123
},
],
'nextToken': 'string'
}
Response Structure
|
describe_metric_filters(**kwargs)¶Lists the specified metric filters. You can list all the metric filters or filter the results by log name, prefix, metric name, and metric namespace. The results are ASCII-sorted by filter name.
See also: AWS API Documentation
Request Syntax
response = client.describe_metric_filters(
logGroupName='string',
filterNamePrefix='string',
nextToken='string',
limit=123,
metricName='string',
metricNamespace='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'metricFilters': [
{
'filterName': 'string',
'filterPattern': 'string',
'metricTransformations': [
{
'metricName': 'string',
'metricNamespace': 'string',
'metricValue': 'string',
'defaultValue': 123.0
},
],
'creationTime': 123,
'logGroupName': 'string'
},
],
'nextToken': 'string'
}
Response Structure
|
describe_subscription_filters(**kwargs)¶Lists the subscription filters for the specified log group. You can list all the subscription filters or filter the results by prefix. The results are ASCII-sorted by filter name.
See also: AWS API Documentation
Request Syntax
response = client.describe_subscription_filters(
logGroupName='string',
filterNamePrefix='string',
nextToken='string',
limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'subscriptionFilters': [
{
'filterName': 'string',
'logGroupName': 'string',
'filterPattern': 'string',
'destinationArn': 'string',
'roleArn': 'string',
'distribution': 'Random'|'ByLogStream',
'creationTime': 123
},
],
'nextToken': 'string'
}
Response Structure
|
filter_log_events(**kwargs)¶Lists log events from the specified log group. You can list all the log events or filter the results using a filter pattern, a time range, and the name of the log stream.
By default, this operation returns as many log events as can fit in 1MB (up to 10,000 log events), or all the events found within the time range that you specify. If the results include a token, then there are more log events available, and you can get additional results by specifying the token in a subsequent call.
See also: AWS API Documentation
Request Syntax
response = client.filter_log_events(
logGroupName='string',
logStreamNames=[
'string',
],
startTime=123,
endTime=123,
filterPattern='string',
nextToken='string',
limit=123,
interleaved=True|False
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'events': [
{
'logStreamName': 'string',
'timestamp': 123,
'message': 'string',
'ingestionTime': 123,
'eventId': 'string'
},
],
'searchedLogStreams': [
{
'logStreamName': 'string',
'searchedCompletely': True|False
},
],
'nextToken': 'string'
}
Response Structure
|
generate_presigned_url(ClientMethod, Params=None, ExpiresIn=3600, HttpMethod=None)¶Generate a presigned url given a client, its method, and arguments
| Parameters: |
|
|---|---|
| Returns: | The presigned url |
get_log_events(**kwargs)¶Lists log events from the specified log stream. You can list all the log events or filter using a time range.
By default, this operation returns as many log events as can fit in a response size of 1MB (up to 10,000 log events). If the results include tokens, there are more log events available. You can get additional log events by specifying one of the tokens in a subsequent call.
See also: AWS API Documentation
Request Syntax
response = client.get_log_events(
logGroupName='string',
logStreamName='string',
startTime=123,
endTime=123,
nextToken='string',
limit=123,
startFromHead=True|False
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'events': [
{
'timestamp': 123,
'message': 'string',
'ingestionTime': 123
},
],
'nextForwardToken': 'string',
'nextBackwardToken': 'string'
}
Response Structure
|
get_paginator(operation_name)¶Create a paginator for an operation.
| Parameters: | operation_name (string) – The operation name. This is the same name
as the method name on the client. For example, if the
method name is create_foo, and you’d normally invoke the
operation as client.create_foo(**kwargs), if the
create_foo operation can be paginated, you can use the
call client.get_paginator("create_foo"). |
|---|---|
| Raises: | OperationNotPageableError – Raised if the operation is not
pageable. You can use the client.can_paginate method to
check if an operation is pageable. |
| Return type: | L{botocore.paginate.Paginator} |
| Returns: | A paginator object. |
get_waiter(waiter_name)¶Lists the tags for the specified log group.
To add tags, use TagLogGroup . To remove tags, use UntagLogGroup .
See also: AWS API Documentation
Request Syntax
response = client.list_tags_log_group(
logGroupName='string'
)
| Parameters: | logGroupName (string) – [REQUIRED] The name of the log group. |
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{
'tags': {
'string': 'string'
}
}
Response Structure
|
put_destination(**kwargs)¶Creates or updates a destination. A destination encapsulates a physical resource (such as a Kinesis stream) and enables you to subscribe to a real-time stream of log events of a different account, ingested using PutLogEvents . Currently, the only supported physical resource is a Amazon Kinesis stream belonging to the same account as the destination.
A destination controls what is written to its Amazon Kinesis stream through an access policy. By default, PutDestination does not set any access policy with the destination, which means a cross-account user cannot call PutSubscriptionFilter against this destination. To enable this, the destination owner must call PutDestinationPolicy after PutDestination .
See also: AWS API Documentation
Request Syntax
response = client.put_destination(
destinationName='string',
targetArn='string',
roleArn='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'destination': {
'destinationName': 'string',
'targetArn': 'string',
'roleArn': 'string',
'accessPolicy': 'string',
'arn': 'string',
'creationTime': 123
}
}
Response Structure
|
put_destination_policy(**kwargs)¶Creates or updates an access policy associated with an existing destination. An access policy is an IAM policy document that is used to authorize claims to register a subscription filter against a given destination.
See also: AWS API Documentation
Request Syntax
response = client.put_destination_policy(
destinationName='string',
accessPolicy='string'
)
| Parameters: |
|
|---|---|
| Returns: | None |
put_log_events(**kwargs)¶Uploads a batch of log events to the specified log stream.
You must include the sequence token obtained from the response of the previous call. An upload in a newly created log stream does not require a sequence token. You can also get the sequence token using DescribeLogStreams .
The batch of events must satisfy the following constraints:
See also: AWS API Documentation
Request Syntax
response = client.put_log_events(
logGroupName='string',
logStreamName='string',
logEvents=[
{
'timestamp': 123,
'message': 'string'
},
],
sequenceToken='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'nextSequenceToken': 'string',
'rejectedLogEventsInfo': {
'tooNewLogEventStartIndex': 123,
'tooOldLogEventEndIndex': 123,
'expiredLogEventEndIndex': 123
}
}
Response Structure
|
put_metric_filter(**kwargs)¶Creates or updates a metric filter and associates it with the specified log group. Metric filters allow you to configure rules to extract metric data from log events ingested through PutLogEvents .
The maximum number of metric filters that can be associated with a log group is 100.
See also: AWS API Documentation
Request Syntax
response = client.put_metric_filter(
logGroupName='string',
filterName='string',
filterPattern='string',
metricTransformations=[
{
'metricName': 'string',
'metricNamespace': 'string',
'metricValue': 'string',
'defaultValue': 123.0
},
]
)
| Parameters: |
|
|---|---|
| Returns: | None |
put_retention_policy(**kwargs)¶Sets the retention of the specified log group. A retention policy allows you to configure the number of days you want to retain log events in the specified log group.
See also: AWS API Documentation
Request Syntax
response = client.put_retention_policy(
logGroupName='string',
retentionInDays=123
)
| Parameters: |
|
|---|---|
| Returns: | None |
put_subscription_filter(**kwargs)¶Creates or updates a subscription filter and associates it with the specified log group. Subscription filters allow you to subscribe to a real-time stream of log events ingested through PutLogEvents and have them delivered to a specific destination. Currently, the supported destinations are:
There can only be one subscription filter associated with a log group. If you are updating an existing filter, you must specify the correct name in filterName . Otherwise, the call will fail because you cannot associate a second filter with a log group.
See also: AWS API Documentation
Request Syntax
response = client.put_subscription_filter(
logGroupName='string',
filterName='string',
filterPattern='string',
destinationArn='string',
roleArn='string',
distribution='Random'|'ByLogStream'
)
| Parameters: |
|
|---|---|
| Returns: | None |
tag_log_group(**kwargs)¶Adds or updates the specified tags for the specified log group.
To list the tags for a log group, use ListTagsLogGroup . To remove tags, use UntagLogGroup .
For more information about tags, see Tag Log Groups in Amazon CloudWatch Logs in the Amazon CloudWatch Logs User Guide .
See also: AWS API Documentation
Request Syntax
response = client.tag_log_group(
logGroupName='string',
tags={
'string': 'string'
}
)
| Parameters: |
|
|---|---|
| Returns: | None |
test_metric_filter(**kwargs)¶Tests the filter pattern of a metric filter against a sample of log event messages. You can use this operation to validate the correctness of a metric filter pattern.
See also: AWS API Documentation
Request Syntax
response = client.test_metric_filter(
filterPattern='string',
logEventMessages=[
'string',
]
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'matches': [
{
'eventNumber': 123,
'eventMessage': 'string',
'extractedValues': {
'string': 'string'
}
},
]
}
Response Structure
|
untag_log_group(**kwargs)¶Removes the specified tags from the specified log group.
To list the tags for a log group, use ListTagsLogGroup . To add tags, use UntagLogGroup .
See also: AWS API Documentation
Request Syntax
response = client.untag_log_group(
logGroupName='string',
tags=[
'string',
]
)
| Parameters: |
|
|---|---|
| Returns: | None |
The available paginators are:
CloudWatchLogs.Paginator.DescribeDestinationsCloudWatchLogs.Paginator.DescribeLogGroupsCloudWatchLogs.Paginator.DescribeLogStreamsCloudWatchLogs.Paginator.DescribeMetricFiltersCloudWatchLogs.Paginator.DescribeSubscriptionFiltersCloudWatchLogs.Paginator.FilterLogEventsCloudWatchLogs.Paginator.DescribeDestinations¶paginator = client.get_paginator('describe_destinations')
paginate(**kwargs)¶Creates an iterator that will paginate through responses from CloudWatchLogs.Client.describe_destinations().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
DestinationNamePrefix='string',
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'destinations': [
{
'destinationName': 'string',
'targetArn': 'string',
'roleArn': 'string',
'accessPolicy': 'string',
'arn': 'string',
'creationTime': 123
},
],
'NextToken': 'string'
}
Response Structure
|
CloudWatchLogs.Paginator.DescribeLogGroups¶paginator = client.get_paginator('describe_log_groups')
paginate(**kwargs)¶Creates an iterator that will paginate through responses from CloudWatchLogs.Client.describe_log_groups().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
logGroupNamePrefix='string',
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'logGroups': [
{
'logGroupName': 'string',
'creationTime': 123,
'retentionInDays': 123,
'metricFilterCount': 123,
'arn': 'string',
'storedBytes': 123
},
],
'NextToken': 'string'
}
Response Structure
|
CloudWatchLogs.Paginator.DescribeLogStreams¶paginator = client.get_paginator('describe_log_streams')
paginate(**kwargs)¶Creates an iterator that will paginate through responses from CloudWatchLogs.Client.describe_log_streams().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
logGroupName='string',
logStreamNamePrefix='string',
orderBy='LogStreamName'|'LastEventTime',
descending=True|False,
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'logStreams': [
{
'logStreamName': 'string',
'creationTime': 123,
'firstEventTimestamp': 123,
'lastEventTimestamp': 123,
'lastIngestionTime': 123,
'uploadSequenceToken': 'string',
'arn': 'string',
'storedBytes': 123
},
],
'NextToken': 'string'
}
Response Structure
|
CloudWatchLogs.Paginator.DescribeMetricFilters¶paginator = client.get_paginator('describe_metric_filters')
paginate(**kwargs)¶Creates an iterator that will paginate through responses from CloudWatchLogs.Client.describe_metric_filters().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
logGroupName='string',
filterNamePrefix='string',
metricName='string',
metricNamespace='string',
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'metricFilters': [
{
'filterName': 'string',
'filterPattern': 'string',
'metricTransformations': [
{
'metricName': 'string',
'metricNamespace': 'string',
'metricValue': 'string',
'defaultValue': 123.0
},
],
'creationTime': 123,
'logGroupName': 'string'
},
],
'NextToken': 'string'
}
Response Structure
|
CloudWatchLogs.Paginator.DescribeSubscriptionFilters¶paginator = client.get_paginator('describe_subscription_filters')
paginate(**kwargs)¶Creates an iterator that will paginate through responses from CloudWatchLogs.Client.describe_subscription_filters().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
logGroupName='string',
filterNamePrefix='string',
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'subscriptionFilters': [
{
'filterName': 'string',
'logGroupName': 'string',
'filterPattern': 'string',
'destinationArn': 'string',
'roleArn': 'string',
'distribution': 'Random'|'ByLogStream',
'creationTime': 123
},
],
'NextToken': 'string'
}
Response Structure
|
CloudWatchLogs.Paginator.FilterLogEvents¶paginator = client.get_paginator('filter_log_events')
paginate(**kwargs)¶Creates an iterator that will paginate through responses from CloudWatchLogs.Client.filter_log_events().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
logGroupName='string',
logStreamNames=[
'string',
],
startTime=123,
endTime=123,
filterPattern='string',
interleaved=True|False,
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'events': [
{
'logStreamName': 'string',
'timestamp': 123,
'message': 'string',
'ingestionTime': 123,
'eventId': 'string'
},
],
'searchedLogStreams': [
{
'logStreamName': 'string',
'searchedCompletely': True|False
},
],
'NextToken': 'string'
}
Response Structure
|