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()
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_log_groups()
describe_log_streams()
describe_metric_filters()
describe_subscription_filters()
filter_log_events()
generate_presigned_url()
get_log_events()
get_paginator()
get_waiter()
put_destination()
put_destination_policy()
put_log_events()
put_metric_filter()
put_retention_policy()
put_subscription_filter()
test_metric_filter()
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. |
create_log_group
(**kwargs)¶Creates a new log group with the specified name. The name of the log group must be unique within a region for an AWS account. You can create up to 500 log groups per account.
You must use the following guidelines when naming a log group:
Request Syntax
response = client.create_log_group(
logGroupName='string'
)
Parameters: | logGroupName (string) -- [REQUIRED] The name of the log group to create. |
---|---|
Returns: | None |
create_log_stream
(**kwargs)¶Creates a new log stream in the specified log group. The name of the log stream must be unique within the log group. There is no limit on the number of log streams that can exist in a log group.
You must use the following guidelines when naming a log stream:
Request Syntax
response = client.create_log_stream(
logGroupName='string',
logStreamName='string'
)
Parameters: |
|
---|---|
Returns: | None |
delete_destination
(**kwargs)¶Deletes the destination with the specified name and eventually disables all the subscription filters that publish to it. This will not delete the physical resource encapsulated by the destination.
Request Syntax
response = client.delete_destination(
destinationName='string'
)
Parameters: | destinationName (string) -- [REQUIRED] The name of destination to delete. |
---|---|
Returns: | None |
delete_log_group
(**kwargs)¶Deletes the log group with the specified name and permanently deletes all the archived log events associated with it.
Request Syntax
response = client.delete_log_group(
logGroupName='string'
)
Parameters: | logGroupName (string) -- [REQUIRED] The name of the log group to delete. |
---|---|
Returns: | None |
delete_log_stream
(**kwargs)¶Deletes a log stream and permanently deletes all the archived log events associated with it.
Request Syntax
response = client.delete_log_stream(
logGroupName='string',
logStreamName='string'
)
Parameters: |
|
---|---|
Returns: | None |
delete_metric_filter
(**kwargs)¶Deletes a metric filter associated with the specified log group.
Request Syntax
response = client.delete_metric_filter(
logGroupName='string',
filterName='string'
)
Parameters: |
|
---|---|
Returns: | None |
delete_retention_policy
(**kwargs)¶Deletes the retention policy of the specified log group. Log events would not expire if they belong to log groups without a retention policy.
Request Syntax
response = client.delete_retention_policy(
logGroupName='string'
)
Parameters: | logGroupName (string) -- [REQUIRED] The name of the log group that is associated with the retention policy to delete. |
---|---|
Returns: | None |
delete_subscription_filter
(**kwargs)¶Deletes a subscription filter associated with the specified log group.
Request Syntax
response = client.delete_subscription_filter(
logGroupName='string',
filterName='string'
)
Parameters: |
|
---|---|
Returns: | None |
describe_destinations
(**kwargs)¶Returns all the destinations that are associated with the AWS account making the request. The list returned in the response is ASCII-sorted by destination name.
By default, this operation returns up to 50 destinations. If there are more destinations to list, the response would contain a nextToken
value in the response body. You can also limit the number of destinations returned in the response by specifying the limit
parameter in the request.
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_log_groups
(**kwargs)¶Returns all the log groups that are associated with the AWS account making the request. The list returned in the response is ASCII-sorted by log group name.
By default, this operation returns up to 50 log groups. If there are more log groups to list, the response would contain a nextToken
value in the response body. You can also limit the number of log groups returned in the response by specifying the limit
parameter in the request.
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)¶Returns all the log streams that are associated with the specified log group. The list returned in the response is ASCII-sorted by log stream name.
By default, this operation returns up to 50 log streams. If there are more log streams to list, the response would contain a nextToken
value in the response body. You can also limit the number of log streams returned in the response by specifying the limit
parameter in the request. This operation has a limit of five transactions per second, after which transactions are throttled.
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)¶Returns all the metrics filters associated with the specified log group. The list returned in the response is ASCII-sorted by filter name.
By default, this operation returns up to 50 metric filters. If there are more metric filters to list, the response would contain a nextToken
value in the response body. You can also limit the number of metric filters returned in the response by specifying the limit
parameter in the request.
Request Syntax
response = client.describe_metric_filters(
logGroupName='string',
filterNamePrefix='string',
nextToken='string',
limit=123
)
Parameters: |
|
---|---|
Return type: | dict |
Returns: | Response Syntax {
'metricFilters': [
{
'filterName': 'string',
'filterPattern': 'string',
'metricTransformations': [
{
'metricName': 'string',
'metricNamespace': 'string',
'metricValue': 'string'
},
],
'creationTime': 123
},
],
'nextToken': 'string'
}
Response Structure
|
describe_subscription_filters
(**kwargs)¶Returns all the subscription filters associated with the specified log group. The list returned in the response is ASCII-sorted by filter name.
By default, this operation returns up to 50 subscription filters. If there are more subscription filters to list, the response would contain a nextToken
value in the response body. You can also limit the number of subscription filters returned in the response by specifying the limit
parameter in the request.
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',
'creationTime': 123
},
],
'nextToken': 'string'
}
Response Structure
|
filter_log_events
(**kwargs)¶Retrieves log events, optionally filtered by a filter pattern from the specified log group. You can provide an optional time range to filter the results on the event timestamp
. You can limit the streams searched to an explicit list of logStreamNames
.
By default, this operation returns as much matching log events as can fit in a response size of 1MB, up to 10,000 log events, or all the events found within a time-bounded scan window. If the response includes a nextToken
, then there is more data to search, and the search can be resumed with a new request providing the nextToken. The response will contain a list of searchedLogStreams
that contains information about which streams were searched in the request and whether they have been searched completely or require further pagination. The limit
parameter in the request. can be used to specify the maximum number of events to return in a page.
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)¶Retrieves log events from the specified log stream. You can provide an optional time range to filter the results on the event timestamp
.
By default, this operation returns as much log events as can fit in a response size of 1MB, up to 10,000 log events. The response will always include a nextForwardToken
and a nextBackwardToken
in the response body. You can use any of these tokens in subsequent GetLogEvents
requests to paginate through events in either forward or backward direction. You can also limit the number of log events returned in the response by specifying the limit
parameter in the request.
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)¶put_destination
(**kwargs)¶Creates or updates a Destination
. A destination encapsulates a physical resource (such as a Kinesis stream) and allows you to subscribe to a real-time stream of log events of a different account, ingested through PutLogEvents
requests. 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 will not be able to call PutSubscriptionFilter
against this destination. To enable that, the destination owner must call PutDestinationPolicy
after PutDestination.
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.
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.
Every PutLogEvents request must include the sequenceToken
obtained from the response of the previous request. An upload in a newly created log stream does not require a sequenceToken
.
The batch of events must satisfy the following constraints:
timestamp
.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
requests.
The maximum number of metric filters that can be associated with a log group is 100.
Request Syntax
response = client.put_metric_filter(
logGroupName='string',
filterName='string',
filterPattern='string',
metricTransformations=[
{
'metricName': 'string',
'metricNamespace': 'string',
'metricValue': 'string'
},
]
)
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.
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
requests and have them delivered to a specific destination. Currently, the supported destinations are:
Destination
) belonging to a different account, for cross-account delivery.Currently there can only be one subscription filter associated with a log group.
Request Syntax
response = client.put_subscription_filter(
logGroupName='string',
filterName='string',
filterPattern='string',
destinationArn='string',
roleArn='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.
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
|