Menu
AWS CodeDeploy
User Guide (API Version 2014-10-06)

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 AWS 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 use CloudWatch Events as part of your AWS CodeDeploy operations:

  • AWS Lambda functions

  • Kinesis streams

  • Amazon SQS queues

  • Built-in targets (CloudWatch alarm actions)

  • 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 AWS CodeDeploy. Before you create event rules for use in your AWS CodeDeploy operations, however, you should do the following:

To create a CloudWatch Events rule for AWS CodeDeploy:

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

  2. In the navigation pane, choose Events.

  3. Choose Create rule, and then under Event selector, choose AWS 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 AWS 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.

    The following shows the setup for an event rule that will be processed whenever a deployment fails to any instance in the MyDeploymentFleet deployment group for the application named MyCodeDeployApp:

  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.