AWS CDK: Add Notifications To Your CodePipeline And Publish Them To Slack Via AWS ChatBot

A simple example on how to enable alerts on your CodePipeline actions trigger them and send those alert notifications to your Slack Channel:

// to build the pipeline: no changes possible after this!
chatBotClientPipeline.buildPipeline();

// sns topic and subscription
const chatbotSnsTopic = new aws_sns.Topic(this, 'chatbotSnsTopic');

chatbotSnsTopic.addSubscription(new aws_sns_subscriptions.UrlSubscription(chatBotSubscriptionEndpoint));

const slackConfig = new SlackChannelConfiguration(this, 'SlackConfig', {
    slackChannelConfigurationName: 'SlackConfig',
    slackWorkspaceId: slackWorkSpaceId,
    slackChannelId: slackChannelId,
    logRetention: RetentionDays.THREE_MONTHS,
    loggingLevel: LoggingLevel.ERROR,
    notificationTopics: [ chatbotSnsTopic ]
});
slackConfig.applyRemovalPolicy(RemovalPolicy.DESTROY);


// choose your notifications
const codePipelineNotifications = new NotificationRule(this, 'CodePipelineNotifications', {
    enabled: true,
    notificationRuleName: 'CodePipelineNotifications',
    detailType: DetailType.BASIC,
    events: [ 
        'codebuild-project-build-state-succeeded',
        'codebuild-project-build-state-failed',
        'codepipeline-pipeline-action-execution-succeeded',
        'codepipeline-pipeline-action-execution-failed',
        'codepipeline-pipeline-action-execution-canceled',
        'codepipeline-pipeline-action-execution-started',
        'codepipeline-pipeline-stage-execution-started',
        'codepipeline-pipeline-stage-execution-succeeded',
        'codepipeline-pipeline-stage-execution-resumed',
        'codepipeline-pipeline-stage-execution-canceled',
        'codepipeline-pipeline-stage-execution-failed',
        'codepipeline-pipeline-pipeline-execution-failed',
        'codepipeline-pipeline-pipeline-execution-canceled',
        'codepipeline-pipeline-pipeline-execution-started',
        'codepipeline-pipeline-pipeline-execution-resumed',
        'codepipeline-pipeline-pipeline-execution-succeeded',
        'codepipeline-pipeline-pipeline-execution-superseded',
        'codepipeline-pipeline-manual-approval-failed',
        'codepipeline-pipeline-manual-approval-needed',
        'codepipeline-pipeline-manual-approval-succeeded',
        'codebuild-project-build-state-failed',
        'codebuild-project-build-state-succeeded',
        'codebuild-project-build-state-in-progress',
        'codebuild-project-build-state-stopped',
        'codebuild-project-build-phase-failure',
        'codebuild-project-build-phase-success', ],
    source: chatBotClientPipeline.pipeline.pipelineArn,
    targets: [ chatbotSnsTopic ],
});

Stay Safe! ☘️