AWS CDK CodeStarNotifications (v1)

1.204.0 · maintenance · verified Fri Apr 17

The `aws-cdk-aws-codestarnotifications` package is part of the AWS Cloud Development Kit (CDK) v1, providing constructs for managing AWS CodeStar Notifications. These constructs allow you to create rules to send notifications about events from various AWS services (like CodeCommit, CodeBuild, CodePipeline) to targets such as Amazon SNS topics or AWS Chatbot. As of version `1.204.0`, AWS CDK v1 is in maintenance mode, with active development focused on CDK v2. New projects are encouraged to use CDK v2.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an AWS CodeStar Notification Rule using AWS CDK v1. It sets up a CodeCommit repository as the notification source and an SNS topic as the target. Notifications are configured for specific CodeCommit events. This code is designed to be part of a larger CDK application.

import os
from aws_cdk import (
    aws_codecommit as codecommit,
    aws_sns as sns,
    aws_codestarnotifications as notifications,
    core as cdk
)

class CodeStarNotificationsExampleStack(cdk.Stack):
    def __init__(self, scope: cdk.App, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Create a CodeCommit repository as the source for notifications
        repo = codecommit.Repository(self, "MyCodeCommitRepo",
            repository_name="my-app-repository-for-notifications"
        )

        # Create an SNS topic as the target for notifications
        # In a real scenario, you'd likely subscribe an email or Lambda to this topic.
        notification_topic = sns.Topic(self, "MyNotificationTopic")

        # Create a Notification Rule
        # This rule will send notifications to the SNS topic for specific CodeCommit events.
        notifications.NotificationRule(self, "RepoNotificationRule",
            source=repo,
            events=[
                "codecommit-repository-comments-on-commits",
                "codecommit-repository-pull-request-created",
                "codecommit-repository-pull-request-merged"
            ],
            targets=[notification_topic],
            detail_type=notifications.DetailType.FULL # Or DetailType.BASIC
        )

# Example of how to synthesize this stack (usually in app.py)
# app = cdk.App()
# CodeStarNotificationsExampleStack(app, "CodeStarNotificationsExampleStack")
# app.synth()

view raw JSON →