NotificationRule

class aws_cdk.aws_codestarnotifications.NotificationRule(scope, id, *, events, source, targets=None, detail_type=None, enabled=None, notification_rule_name=None)

Bases: Resource

A new notification rule.

Resource:

AWS::CodeStarNotifications::NotificationRule

ExampleMetadata:

infused

Example:

import aws_cdk.aws_codestarnotifications as notifications
import aws_cdk.aws_codebuild as codebuild
import aws_cdk.aws_sns as sns
import aws_cdk.aws_chatbot as chatbot


project = codebuild.PipelineProject(self, "MyProject")

topic = sns.Topic(self, "MyTopic1")

slack = chatbot.SlackChannelConfiguration(self, "MySlackChannel",
    slack_channel_configuration_name="YOUR_CHANNEL_NAME",
    slack_workspace_id="YOUR_SLACK_WORKSPACE_ID",
    slack_channel_id="YOUR_SLACK_CHANNEL_ID"
)

rule = notifications.NotificationRule(self, "NotificationRule",
    source=project,
    events=["codebuild-project-build-state-succeeded", "codebuild-project-build-state-failed"
    ],
    targets=[topic]
)
rule.add_target(slack)
Parameters:
  • scope (Construct) –

  • id (str) –

  • events (Sequence[str]) – A list of event types associated with this notification rule. For a complete list of event types and IDs, see Notification concepts in the Developer Tools Console User Guide.

  • source (INotificationRuleSource) – The Amazon Resource Name (ARN) of the resource to associate with the notification rule. Currently, Supported sources include pipelines in AWS CodePipeline, build projects in AWS CodeBuild, and repositories in AWS CodeCommit in this L2 constructor.

  • targets (Optional[Sequence[INotificationRuleTarget]]) – The targets to register for the notification destination. Default: - No targets are added to the rule. Use addTarget() to add a target.

  • detail_type (Optional[DetailType]) – The level of detail to include in the notifications for this resource. BASIC will include only the contents of the event as it would appear in AWS CloudWatch. FULL will include any supplemental information provided by AWS CodeStar Notifications and/or the service for the resource for which the notification is created. Default: DetailType.FULL

  • enabled (Optional[bool]) – The status of the notification rule. If the enabled is set to DISABLED, notifications aren’t sent for the notification rule. Default: true

  • notification_rule_name (Optional[str]) – The name for the notification rule. Notification rule names must be unique in your AWS account. Default: - generated from the id

Methods

add_target(target)

Adds target to notification rule.

Parameters:

target (INotificationRuleTarget) – The SNS topic or AWS Chatbot Slack target.

Return type:

bool

apply_removal_policy(policy)

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters:

policy (RemovalPolicy) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

node

The construct tree node associated with this construct.

notification_rule_arn

codestar-notifications:::notificationrule/01234abcde).

Attribute:

true

Type:

The ARN of the notification rule (i.e. arn

Type:

aws

stack

The stack in which this resource is defined.

Static Methods

classmethod from_notification_rule_arn(scope, id, notification_rule_arn)

Import an existing notification rule provided an ARN.

Parameters:
  • scope (Construct) – The parent creating construct.

  • id (str) – The construct’s name.

  • notification_rule_arn (str) – Notification rule ARN (i.e. arn:aws:codestar-notifications:::notificationrule/01234abcde).

Return type:

INotificationRule

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool