Menu
AWS CodePipeline
User Guide (API Version 2015-07-09)

Tutorial: Set Up a CloudWatch Events Rule to Receive Email Notifications for Pipeline State Changes

After you set up a pipeline, you can set up a CloudWatch Events rule to send notifications whenever there are changes to the execution state of your pipelines, or in the stages or actions in your pipelines. For more information on using CloudWatch Events to set up notifications for pipeline state changes, see Detect and React to Changes in Pipeline State with Amazon CloudWatch Events.

In this tutorial, you configure a notification to send an email when a pipeline's state changes to FAILED. This tutorial uses an input transformer method when creating the CloudWatch Events rule. It transforms the message schema details to deliver the message in human-readable text.

Step 1: Set Up an Email Notification Using Amazon SNS

Amazon SNS coordinates use of topics to deliver messages to subscribing endpoints or clients. Use Amazon SNS to create a notification topic and then subscribe to the topic using your email address. The Amazon SNS topic will be added as a target to your CloudWatch Events rule. For more information, see the Amazon Simple Notification Service Developer Guide .

  1. Create or identify a topic in Amazon SNS. AWS CodePipeline will use CloudWatch Events to send notifications to this topic through Amazon SNS. To create a topic:

    1. Open the Amazon SNS console at https://console.aws.amazon.com/sns.

    2. Choose Create topic.

    3. In the Create new topic dialog box, for Topic name, type a name for the topic (for example, PipelineNotificationTopic).

      
                Create the notification topic using Amazon SNS.
    4. Choose Create topic.

      For more information, see Create a Topic in the Amazon SNS Developer Guide.

  2. Subscribe one or more recipients to the topic to receive email notifications. To subscribe a recipient to a topic:

    1. In the Amazon SNS console, from the Topics list, select the check box next to your new topic. Choose Actions, Subscribe to topic.

    2. In the Create subscription dialog box, verify that an ARN appears in Topic ARN.

    3. For Protocol, choose Email.

    4. For Endpoint, type the recipient's full email address. Compare your results to the following:

      
                Complete the notification creation by subscribing to the topic.
    5. Choose Create Subscription.

    6. Amazon SNS sends a subscription confirmation email to the recipient. To receive email notifications, the recipient must choose the Confirm subscription link in this email. After the recipient clicks the link, if successfully subscribed, Amazon SNS displays a confirmation message in the recipient's web browser.

    For more information, see Subscribe to a Topic in the Amazon SNS Developer Guide.

Step 2: Create a Rule and Add the SNS Topic as the Target

Create a CloudWatch Events notification rule with AWS CodePipeline as the event source.

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. In the navigation pane, choose Events.

  3. Choose Create rule. Under Event source, choose AWS CodePipeline. For Event Type, choose Pipeline Execution State Change.

  4. Choose Specific state(s), and choose FAILED.

  5. Choose Edit to open the JSON editor for the Event Pattern Preview pane. Add the pipeline parameter with the name of your pipeline as shown in the following example for a pipeline named "myPipeline."

    
            A pipeline name can be edited manually in the JSON structure for the
              rule.
  6. For Targets, choose Add target.

  7. In the list of targets, choose SNS topic. For Topic, enter the topic you created.

  8. Expand Configure input, and then choose Input Transformer.

  9. In the Input Path box, type the following key-value pairs.

    Copy
    { “pipeline” : “$.detail.pipeline” }

    In the Input Template box, type the following:

    Copy
    "The Pipeline <pipeline> has failed."
  10. Choose Configure details.

  11. On the Configure rule details page, type a name and an optional description. For State, leave the Enabled box selected.

  12. Choose Create rule.

  13. Confirm that AWS CodePipeline is now sending build notifications. For example, check to see if the build notification emails are now in your inbox.

  14. To change a rule's behavior, in the CloudWatch console, choose the rule, and then choose Actions, Edit. Edit the rule, choose Configure details, and then choose Update rule.

    To stop using a rule to send build notifications, in the CloudWatch console, choose the rule, and then choose Actions, Disable.

    To delete a rule, in the CloudWatch console, choose the rule, and then choose Actions, Delete.

Step 3: Clean Up Resources

After you complete this tutorial, you should delete the pipeline and the resources it uses so you will not be charged for continued use of those resources.

For information about how to clean up the SNS notification and delete the Amazon CloudWatch Events rule, see Clean Up (Unsubscribe from an Amazon SNS Topic) and reference DeleteRule in the Amazon CloudWatch Events API Reference.