AWS CodeDeploy Event Rule for Slack Notifications | AWS CloudWatch Events

Implementing Slack Notifications for AWS CodeDeploy Deployments

Prev Question Next Question

Question

Company ABC used AWS CodeDeploy to deploy one web application to AWS services including EC2

CodeDeploy is running well however your manager wants to get in time notifications in Slack channel when a new deployment has succeeded or failed.

You were told to implement this in AWS CloudWatch Events.

The target of the Event rule would be a Lambda function that applies only to deployments.

Which event pattern is correct for the rule?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - A.

CloudWatch Events rule is great to help monitor the status of CodeDeploy.

Details can be found in.

https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-cloudwatch-events.html.

This scenario is a typical use case according to this document.

Option A is CORRECT: Because this case needs to monitor the status change of deployment so the “detail-type” would be "CodeDeploy Deployment State-change Notification".

Option B is incorrect: Because the "detail-type" of "CodeDeploy Instance State-change Notification" is incorrect.

Option C is incorrect: Because the "detail-type" of "AWS API Call via CloudTrail" should not be used.

Option D is incorrect: Because the "detail-type" is incorrect.

Also the states of"FAILURE" and "SUCCESS" need to be included.

The correct answer for the given scenario is A.

Explanation:

To implement notifications in Slack channel when a new deployment has succeeded or failed using AWS CloudWatch Events, we need to create a rule that listens to events from AWS CodeDeploy service and sends them to the Lambda function as a target. The event pattern used in the rule determines which events trigger the rule.

Option A is the correct event pattern for the given scenario because it listens to events with the following attributes:

  • Source: aws.codedeploy
  • Detail-type: CodeDeploy Deployment State-change Notification
  • Detail: State: FAILURE or SUCCESS

This means that the rule will trigger only for events related to CodeDeploy deployment state changes and the only states that trigger the rule are FAILURE and SUCCESS. This fits perfectly with the scenario's requirement to send notifications only when a deployment has succeeded or failed.

Option B is incorrect because it listens to events related to CodeDeploy instance state changes, not deployment state changes. Additionally, it includes states such as READY and START that are not relevant to the scenario.

Option C is incorrect because it listens to AWS API calls via CloudTrail, not CodeDeploy deployment state changes.

Option D is incorrect because it listens to events related to CodeDeploy instance state changes, not deployment state changes. Additionally, it only triggers the rule for states of FAILURE and START, which does not cover the scenario's requirement to send notifications for successful deployments.