Coder Social home page Coder Social logo

gidihup / code-pipeline-slack-notifier Goto Github PK

View Code? Open in Web Editor NEW

This project forked from symphoniacloud/code-pipeline-slack-notifier

0.0 0.0 0.0 149 KB

Post updates to a Slack channel for pipeline events generated by AWS Code Pipeline.

License: Apache License 2.0

JavaScript 45.43% Shell 54.57%

code-pipeline-slack-notifier's Introduction

Code Pipeline Slack Notifier

This small Lambda app will post updates to a Slack channel for pipeline events generated by AWS Code Pipeline.

Screenshot

If you have Code Pipelines in multiple accounts / sub-accounts and/or regions then you'll need to deploy this application to each account+region combo that you have your Code Pipelines in.

Prerequisites

  • AWS Account using Code Pipeline. Otherwise there's not much point to this. :)
  • Slack account, and an incoming webhook URL you can use to post to it. This will be something like https://hooks.slack.com/services/....
  • An AWS user with sufficient privileges to deploy the application from the AWS Serverless Application Repository
  • An S3 bucket that you can use as a location of your build artifact. You should have write privileges to this from your AWS user.
  • Locally: At least relatively recent version of the AWS CLI, and Node if you are building from source

Serverless Application Repository App

The easiest way to use this application is via the AWS Serverless Application Repo. You can find it here .

If you want to consume the SAR app as a nested stack (great for putting under source control!) then you can use sam init to create a template project as follows (This requires the SAM CLI):

 $ sam init --location gh:symphoniacloud/code-pipeline-slack-notifier

.. and follow the prompts. Once complete, change into the generated directory and run deploy.sh to complete, or put the generated project into your typical deployment pipeline flow.

If you can't, or don't want to, use the SAR version, then carry on here...

Setup

  1. Run the following from a terminal, substituting YOUR_S3_BUCKET for the S3 bucket described above, and YOUR-INCOMING-WEBHOOK-URL for the Slack URL described above:

    $ npm install
    
    $ npm run dist
    
    $ aws cloudformation package --template-file sam.yaml --s3-bucket YOUR_S3_BUCKET --output-template-file target/packaged-template.yaml
    
    $ aws cloudformation deploy --template-file ./target/packaged-template.yaml --stack-name cp-slack-notifier --parameter-overrides SlackUrl=YOUR-INCOMING-WEBHOOK-URL --capabilities CAPABILITY_IAM

Testing

If you'd like to test the app, you can configure the following test event in the Lambda console, and test there:

{
  "version": "0",
  "id": "d852b55d-a96a-e396-2e34-107bc39d1e21",
  "detail-type": "CodePipeline Pipeline Execution State Change",
  "source": "aws.codepipeline",
  "account": "123456789012",
  "time": "2018-02-23T16:54:45Z",
  "region": "us-west-2",
  "resources": [
    "arn:aws:codepipeline:us-west-2:123456789012:serverless-weather-build-CodePipeline-ABCDEFGHIJKL"
  ],
  "detail": {
    "pipeline": "serverless-weather-build-CodePipeline-ABCDEFGHIJKL",
    "execution-id": "1620f6b6-6731-4d93-aa3c-123456789012",
    "state": "STARTED",
    "version": 1
  }
}

Possible extensions / modifications

  1. To change which types of events you want to be notified about you can specify a filter within the Cloudwatch Event rule. For instance, to only notify on failed runs of the pipeline, update the EventPattern section of the CodePipelineEvent in the sam.yml file as follows:

      EventPattern:
        source:
        - aws.codepipeline
        detail-type:
        - CodePipeline Pipeline Execution State Change
        detail:
          state:
          - FAILED
  2. Similarly, to only notify for certain pipelines you can use the pipeline attribute of the detail element. For more details of event filtering, see the documentation at http://docs.aws.amazon.com/codepipeline/latest/userguide/detect-state-changes-cloudwatch-events.html

  3. You can also listen for different, more granular, events within CodePipeline. This is also detailed in the link above.

  4. You can perform filtering in code, in the Lambda function, but that will mean your Lambda function is getting triggered more often, which can lead to increased costs.

  5. Another nice extension would be different types of message for different kinds of events, or posting to different channels for different pipelines. Either of these are possible by modifying the message POSTed to Slack. See https://api.slack.com/docs/messages for more details

Teardown

To teardown the notifier delete the stack through the Web Console, or use the incantation below:

$ aws cloudformation delete-stack --stack-name cp-slack-notifier

Copyright 2017, Symphonia LLC

code-pipeline-slack-notifier's People

Contributors

mikebroberts avatar alexanderkuehn avatar petrgazarov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.