question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[pipelines] how to add notifications to a CDK pipeline? or: expose underlying CodePipeline object

See original GitHub issue

As far as I can tell, there is no way with the current CDK pipeline API to add codestarnotifications to the underlying CodePipeline, because there is no way to get the ARN of the CodePipeline.

The CdkPipeline has a private variable that holds the reference to the CodePipeline, but we can’t access it. I imagine that it would be useful for developers to have access to this for many other reasons as well.

Use Case

There is no way to set up notifications for a CDK pipeline.

Proposed Solution

Change CdkPipeline private readonly _pipeline member variable to public.

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:11
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
wilhen01commented, Jul 16, 2021

You can get codestar notifications working with CDK pipelines using the below code snippet. pipeline.codePipeline exposes the underlying CodePipeline object.

import * as pipelines from '@aws-cdk/pipelines';
import { DetailType, NotificationRule } from '@aws-cdk/aws-codestarnotifications';
import { Topic } from '@aws-cdk/aws-sns';
import { Construct, Fn, Stack, StackProps } from '@aws-cdk/core';

const pipeline = new pipelines.CdkPipeline(this, 'Deployer', {
      cloudAssemblyArtifact,
      sourceAction,
      synthAction,
    });
    
const slackNotificationTopicArn = Fn.importValue(Exports.SlackStatusNotificationsTopic);
const targetTopic = Topic.fromTopicArn(this, 'topic', slackNotificationTopicArn);

new NotificationRule(this, 'Notification', {
      detailType: DetailType.BASIC,
      events: ['codepipeline-pipeline-pipeline-execution-failed'],
      source: pipeline.codePipeline,
      targets: [targetTopic],
    });
7reactions
federicobareracommented, Oct 13, 2021

@TomaszSzusterTR

EDIT 2:

Adding pipeline.buildPipeline() between the CodePipeline and the Notification creates the notification correctly.

import {
  CodePipeline,
} from '@aws-cdk/pipelines';

const pipeline = new CodePipeline(this, 'Pipeline', {
      synth,
      pipelineName: stackName
    });

pipeline.buildPipeline()

const rule = new NotificationRule(this, 'Notification', {
      detailType: DetailType.BASIC,
      events: [
        'codepipeline-pipeline-pipeline-execution-started',
        'codepipeline-pipeline-pipeline-execution-failed',
        'codepipeline-pipeline-pipeline-execution-succeeded'
      ],
      source: pipeline.pipeline,
      targets: [targetTopic]
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

interface PipelineNotifyOnOptions · AWS CDK
A list of event types associated with this notification rule for CodePipeline Pipeline. detailType? DetailType, The level of detail to include in the ......
Read more >
Add Manual Approval - Advanced CDK Workshop
You can use these to add validations like manual or automated gates to your pipeline. We recommend putting manual approval gates in the...
Read more >
Create New Pipeline - AWS CDK Workshop
Return to the file lib/pipeline-stack.ts and edit as follows: import * as cdk from ... CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines"; ...
Read more >
Enhanced CI/CD with AWS CDK - AWS Online Tech Talks
Learning Objectives: *Learn how to use AWS CDK and AWS CodePipeline to build and deploy a library of custom constructs that will enable...
Read more >
AWS CodePipeline - Noise
CDK Pipelines are self-updating: if you add application stages or stacks, then the pipeline automatically reconfigures itself to deploy those new stages ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found