Monitoring deployments with Amazon CloudWatch Events - Amazon CodeDeploy
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Monitoring deployments with Amazon CloudWatch Events

You can use Amazon CloudWatch Events to detect and react to changes in the state of an instance or a deployment (an "event") in your CodeDeploy operations. Then, based on rules you create, CloudWatch Events will invoke one or more target actions when a deployment or instance enters the state you specify in a rule. Depending on the type of state change, you might want to send notifications, capture state information, take corrective action, initiate events, or take other actions. You can select the following types of targets when using CloudWatch Events as part of your CodeDeploy operations:

  • Amazon Lambda functions

  • Kinesis streams

  • Amazon SQS queues

  • Built-in targets (EC2 CreateSnapshot API call, EC2 RebootInstances API call, EC2 StopInstances API call , and EC2 TerminateInstances API call)

  • Amazon SNS topics

The following are some use cases:

  • Use a Lambda function to pass a notification to a Slack channel whenever deployments fail.

  • Push data about deployments or instances to a Kinesis stream to support comprehensive, real-time status monitoring.

  • Use CloudWatch alarm actions to automatically stop, terminate, reboot, or recover Amazon EC2 instances when a deployment or instance event you specify occurs.

The remainder of this topic describes the basic procedure for creating a CloudWatch Events rule for CodeDeploy. Before you create event rules for use in your CodeDeploy operations, however, you should do the following:

To create a CloudWatch Events rule for CodeDeploy:
  1. Open the CloudWatch console at https://console.amazonaws.cn/cloudwatch/.

  2. In the navigation pane, choose Events.

  3. Choose Create rule, and then under Event selector, choose Amazon CodeDeploy.

  4. Specify a detail type:

    • To make a rule that applies to all state changes of both instances and deployments, choose Any detail type, and then skip to step 6.

    • To make a rule that applies to instances only, choose Specific detail type, and then choose CodeDeploy Instance State-change Notification.

    • To make a rule that applies to deployments only, choose Specific detail type, and then choose CodeDeploy Deployment State-change Notification.

  5. Specify the state changes the rule applies to:

    • To make a rule that applies to all state changes, choose Any state.

    • To make a rule that applies to some state changes only, choose Specific state(s), and then choose one or more status values from the list. The following table lists the status values you can choose:

      Deployment status values Instance status values

      FAILURE

      START

      STOP

      QUEUED

      READY

      SUCCESS

      FAILURE

      START

      READY

      SUCCESS

  6. Specify which CodeDeploy applications the rule applies to:

    • To make a rule that applies to all applications, choose Any application, and then skip to step 8.

    • To make a rule that applies to one application only, choose Specific application, and then choose the name of the application from the list.

  7. Specify which deployment groups the rule applies to:

    • To make a rule that applies to all deployment groups associated with the selected application, choose Any deployment group.

    • To make a rule that applies to only one of the deployment groups associated with the selected application, choose Specific deployment group(s), and then choose the name of the deployment group from the list.

  8. Review your rule setup to make sure it meets your event-monitoring requirements.

  9. In the Targets area, choose Add target*.

  10. In the Select target type list, choose the type of target you have prepared to use with this rule, and then configure any additional options required by that type.

  11. Choose Configure details.

  12. On the Configure rule details page, type a name and description for the rule, and then choose the State box to enable to rule now.

  13. If you're satisfied with the rule, choose Create rule.