OnEventOptions

class aws_cdk.aws_events.OnEventOptions(*, description=None, event_pattern=None, rule_name=None, target=None)

Bases: object

Standard set of options for onXxx event handlers on construct.

Parameters
  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Optional[EventPattern]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

Example:

# Example automatically generated from non-compiling source. May contain errors.
import aws_cdk.aws_config as config
import aws_cdk.aws_lambda as lambda_
import aws_cdk.aws_sns as sns
import aws_cdk.aws_events_targets as targets

# Lambda function containing logic that evaluates compliance with the rule.
eval_compliance_fn = lambda_.Function(self, "CustomFunction",
    code=lambda_.AssetCode.from_inline("exports.handler = (event) => console.log(event);"),
    handler="index.handler",
    runtime=lambda_.Runtime.NODEJS_12_X
)

# A custom rule that runs on configuration changes of EC2 instances
custom_rule = config.CustomRule(self, "Custom",
    configuration_changes=True,
    lambda_function=eval_compliance_fn,
    rule_scope=config.RuleScope.from_resource([config.ResourceType.EC2_INSTANCE])
)

# A rule to detect stack drifts
drift_rule = config.CloudFormationStackDriftDetectionCheck(self, "Drift")

# Topic to which compliance notification events will be published
compliance_topic = sns.Topic(self, "ComplianceTopic")

# Send notification on compliance change events
drift_rule.on_compliance_change("ComplianceChange",
    target=targets.SnsTopic(compliance_topic)
)

Attributes

description

A description of the rule’s purpose.

Default
  • No description

Return type

Optional[str]

event_pattern

Additional restrictions for the event to route to the specified target.

The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering.

Default
  • No additional filtering based on an event pattern.

See

https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html

Return type

Optional[EventPattern]

rule_name

A name for the rule.

Default

AWS CloudFormation generates a unique physical ID.

Return type

Optional[str]

target

The target to register for the event.

Default
  • No target is added to the rule. Use addTarget() to add a target.

Return type

Optional[IRuleTarget]