NotificationRule
- class aws_cdk.aws_codestarnotifications.NotificationRule(scope, id, *, events, source, targets=None, created_by=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], notification_rule_name="MyNotificationRuleName", enabled=True, # The default is true detail_type=notifications.DetailType.FULL, # The default is FULL created_by="Jone Doe" ) 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. UseaddTarget()
to add a target.created_by (
Optional
[str
]) – The name or email alias of the person who created the notification rule. If not specified, it means that the creator’s alias is not provided. Default: - No alias provideddetail_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.FULLenabled (
Optional
[bool
]) – The status of the notification rule. If the enabled is set to DISABLED, notifications aren’t sent for the notification rule. Default: truenotification_rule_name (
Optional
[str
]) – The name for the notification rule. Notification rule names must be unique in your AWS account. Default: - generated from theid
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 tree node.
- 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:
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.
- classmethod is_owned_resource(construct)
Returns true if the construct was created by CDK, and false otherwise.
- Parameters:
construct (
IConstruct
) –- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
) –- Return type:
bool