Table of Contents
CloudWatchEvents.Client¶A low-level client representing Amazon CloudWatch Events:
client = session.create_client('events')
These are the available methods:
can_paginate()delete_rule()describe_event_bus()describe_rule()disable_rule()enable_rule()generate_presigned_url()get_paginator()get_waiter()list_rule_names_by_target()list_rules()list_targets_by_rule()put_events()put_permission()put_rule()put_targets()remove_permission()remove_targets()test_event_pattern()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. |
delete_rule(**kwargs)¶Deletes the specified rule.
You must remove all targets from a rule using RemoveTargets before you can delete the rule.
When you delete a rule, incoming events might continue to match to the deleted rule. Please allow a short period of time for changes to take effect.
See also: AWS API Documentation
Request Syntax
response = client.delete_rule(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] The name of the rule. |
|---|---|
| Returns: | None |
describe_event_bus()¶Displays the external AWS accounts that are permitted to write events to your account using your account’s event bus, and the associated policy. To enable your account to receive events from other accounts, use PutPermission .
See also: AWS API Documentation
Request Syntax
response = client.describe_event_bus()
| Return type: | dict |
|---|---|
| Returns: | Response Syntax{
'Name': 'string',
'Arn': 'string',
'Policy': 'string'
}
Response Structure
|
describe_rule(**kwargs)¶Describes the specified rule.
See also: AWS API Documentation
Request Syntax
response = client.describe_rule(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] The name of the rule. |
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{
'Name': 'string',
'Arn': 'string',
'EventPattern': 'string',
'ScheduleExpression': 'string',
'State': 'ENABLED'|'DISABLED',
'Description': 'string',
'RoleArn': 'string'
}
Response Structure
|
disable_rule(**kwargs)¶Disables the specified rule. A disabled rule won’t match any events, and won’t self-trigger if it has a schedule expression.
When you disable a rule, incoming events might continue to match to the disabled rule. Please allow a short period of time for changes to take effect.
See also: AWS API Documentation
Request Syntax
response = client.disable_rule(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] The name of the rule. |
|---|---|
| Returns: | None |
enable_rule(**kwargs)¶Enables the specified rule. If the rule does not exist, the operation fails.
When you enable a rule, incoming events might not immediately start matching to a newly enabled rule. Please allow a short period of time for changes to take effect.
See also: AWS API Documentation
Request Syntax
response = client.enable_rule(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] The name of the rule. |
|---|---|
| Returns: | None |
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_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)¶list_rule_names_by_target(**kwargs)¶Lists the rules for the specified target. You can see which of the rules in Amazon CloudWatch Events can invoke a specific target in your account.
See also: AWS API Documentation
Request Syntax
response = client.list_rule_names_by_target(
TargetArn='string',
NextToken='string',
Limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'RuleNames': [
'string',
],
'NextToken': 'string'
}
Response Structure
|
list_rules(**kwargs)¶Lists your Amazon CloudWatch Events rules. You can either list all the rules or you can provide a prefix to match to the rule names.
See also: AWS API Documentation
Request Syntax
response = client.list_rules(
NamePrefix='string',
NextToken='string',
Limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'Rules': [
{
'Name': 'string',
'Arn': 'string',
'EventPattern': 'string',
'State': 'ENABLED'|'DISABLED',
'Description': 'string',
'ScheduleExpression': 'string',
'RoleArn': 'string'
},
],
'NextToken': 'string'
}
Response Structure
|
list_targets_by_rule(**kwargs)¶Lists the targets assigned to the specified rule.
See also: AWS API Documentation
Request Syntax
response = client.list_targets_by_rule(
Rule='string',
NextToken='string',
Limit=123
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'Targets': [
{
'Id': 'string',
'Arn': 'string',
'RoleArn': 'string',
'Input': 'string',
'InputPath': 'string',
'InputTransformer': {
'InputPathsMap': {
'string': 'string'
},
'InputTemplate': 'string'
},
'KinesisParameters': {
'PartitionKeyPath': 'string'
},
'RunCommandParameters': {
'RunCommandTargets': [
{
'Key': 'string',
'Values': [
'string',
]
},
]
},
'EcsParameters': {
'TaskDefinitionArn': 'string',
'TaskCount': 123
}
},
],
'NextToken': 'string'
}
Response Structure
|
put_events(**kwargs)¶Sends custom events to Amazon CloudWatch Events so that they can be matched to rules.
See also: AWS API Documentation
Request Syntax
response = client.put_events(
Entries=[
{
'Time': datetime(2015, 1, 1),
'Source': 'string',
'Resources': [
'string',
],
'DetailType': 'string',
'Detail': 'string'
},
]
)
| Parameters: | Entries (list) – [REQUIRED] The entry that defines an event in your system. You can specify several parameters for the entry such as the source and type of the event, resources associated with the event, and so on.
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{
'FailedEntryCount': 123,
'Entries': [
{
'EventId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
}
Response Structure
|
put_permission(**kwargs)¶Running PutPermission permits the specified AWS account to put events to your account’s default event bus . CloudWatch Events rules in your account are triggered by these events arriving to your default event bus.
For another account to send events to your account, that external account must have a CloudWatch Events rule with your account’s default event bus as a target.
To enable multiple AWS accounts to put events to your default event bus, run PutPermission once for each of these accounts.
See also: AWS API Documentation
Request Syntax
response = client.put_permission(
Action='string',
Principal='string',
StatementId='string'
)
| Parameters: |
|
|---|---|
| Returns: | None |
put_rule(**kwargs)¶Creates or updates the specified rule. Rules are enabled by default, or based on value of the state. You can disable a rule using DisableRule .
When you create or update a rule, incoming events might not immediately start matching to new or updated rules. Please allow a short period of time for changes to take effect.
A rule must contain at least an EventPattern or ScheduleExpression. Rules with EventPatterns are triggered when a matching event is observed. Rules with ScheduleExpressions self-trigger based on the given schedule. A rule can have both an EventPattern and a ScheduleExpression, in which case the rule triggers on matching events as well as on a schedule.
Most services in AWS treat : or / as the same character in Amazon Resource Names (ARNs). However, CloudWatch Events uses an exact match in event patterns and rules. Be sure to use the correct ARN characters when creating event patterns so that they match the ARN syntax in the event you want to match.
See also: AWS API Documentation
Request Syntax
response = client.put_rule(
Name='string',
ScheduleExpression='string',
EventPattern='string',
State='ENABLED'|'DISABLED',
Description='string',
RoleArn='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'RuleArn': 'string'
}
Response Structure
|
put_targets(**kwargs)¶Adds the specified targets to the specified rule, or updates the targets if they are already associated with the rule.
Targets are the resources that are invoked when a rule is triggered.
You can configure the following as targets for CloudWatch Events:
Note that creating rules with built-in targets is supported only in the AWS Management Console.
For some target types, PutTargets provides target-specific parameters. If the target is an Amazon Kinesis stream, you can optionally specify which shard the event goes to by using the KinesisParameters argument. To invoke a command on multiple EC2 instances with one rule, you can use the RunCommandParameters field.
To be able to make API calls against the resources that you own, Amazon CloudWatch Events needs the appropriate permissions. For AWS Lambda and Amazon SNS resources, CloudWatch Events relies on resource-based policies. For EC2 instances, Amazon Kinesis streams, and AWS Step Functions state machines, CloudWatch Events relies on IAM roles that you specify in the RoleARN argument in PutTargets . For more information, see Authentication and Access Control in the Amazon CloudWatch Events User Guide .
If another AWS account is in the same region and has granted you permission (using PutPermission ), you can set that account’s event bus as a target of the rules in your account. To send the matched events to the other account, specify that account’s event bus as the Arn when you run PutTargets . For more information about enabling cross-account events, see PutPermission .
Input , InputPath and InputTransformer are mutually exclusive and optional parameters of a target. When a rule is triggered due to a matched event:
$.detail ), then only the part of the event specified in the path is passed to the target (for example, only the detail part of the event is passed).When you specify Input , InputPath , or InputTransformer , you must use JSON dot notation, not bracket notation.
When you add targets to a rule and the associated rule triggers soon after, new or updated targets might not be immediately invoked. Please allow a short period of time for changes to take effect.
This action can partially fail if too many requests are made at the same time. If that happens, FailedEntryCount is non-zero in the response and each entry in FailedEntries provides the ID of the failed target and the error code.
See also: AWS API Documentation
Request Syntax
response = client.put_targets(
Rule='string',
Targets=[
{
'Id': 'string',
'Arn': 'string',
'RoleArn': 'string',
'Input': 'string',
'InputPath': 'string',
'InputTransformer': {
'InputPathsMap': {
'string': 'string'
},
'InputTemplate': 'string'
},
'KinesisParameters': {
'PartitionKeyPath': 'string'
},
'RunCommandParameters': {
'RunCommandTargets': [
{
'Key': 'string',
'Values': [
'string',
]
},
]
},
'EcsParameters': {
'TaskDefinitionArn': 'string',
'TaskCount': 123
}
},
]
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'FailedEntryCount': 123,
'FailedEntries': [
{
'TargetId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
}
Response Structure
|
remove_permission(**kwargs)¶Revokes the permission of another AWS account to be able to put events to your default event bus. Specify the account to revoke by the StatementId value that you associated with the account when you granted it permission with PutPermission . You can find the StatementId by using DescribeEventBus .
See also: AWS API Documentation
Request Syntax
response = client.remove_permission(
StatementId='string'
)
| Parameters: | StatementId (string) – [REQUIRED] The statement ID corresponding to the account that is no longer allowed to put events to the default event bus. |
|---|---|
| Returns: | None |
remove_targets(**kwargs)¶Removes the specified targets from the specified rule. When the rule is triggered, those targets are no longer be invoked.
When you remove a target, when the associated rule triggers, removed targets might continue to be invoked. Please allow a short period of time for changes to take effect.
This action can partially fail if too many requests are made at the same time. If that happens, FailedEntryCount is non-zero in the response and each entry in FailedEntries provides the ID of the failed target and the error code.
See also: AWS API Documentation
Request Syntax
response = client.remove_targets(
Rule='string',
Ids=[
'string',
]
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'FailedEntryCount': 123,
'FailedEntries': [
{
'TargetId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
}
Response Structure
|
test_event_pattern(**kwargs)¶Tests whether the specified event pattern matches the provided event.
Most services in AWS treat : or / as the same character in Amazon Resource Names (ARNs). However, CloudWatch Events uses an exact match in event patterns and rules. Be sure to use the correct ARN characters when creating event patterns so that they match the ARN syntax in the event you want to match.
See also: AWS API Documentation
Request Syntax
response = client.test_event_pattern(
EventPattern='string',
Event='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'Result': True|False
}
Response Structure
|
The available paginators are: