AWS CodeDeploy: Configuring CloudWatch Event Rule for Slack Notifications

Configuring CloudWatch Event Rule for Slack Notifications

Prev Question Next Question

Question

Your team has created a new deployment in AWS CodeDeploy service.

It automates the deployments for a new Node.js application to Amazon EC2 instances.

In order to pass a notification to a Slack channel whenever deployments fail, a DevOps engineer configured a CloudWatch Event rule as follows:

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - C.

In the CloudWatch Event rule, the detail-type is incorrect as it should check the state change of CodeDeploy deployments instead of instances.

As the Event rule cannot find the deployment failures, the Lambda function is not triggered and no notifications are sent to the Slack channel.

To fix the problem, the detail-type needs to be modified.

References can be found in https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-cloudwatch-events.html.

Option A is incorrect: Because there is no need to replace the Lambda function with an SNS topic.

The event pattern in the CloudWatch Event rule should be modified.

Option B is incorrect: It is improper to match all CodeDeploy events since only the deployment failure events are required.

Option C is CORRECT: The below event pattern should be configured:

{

"source": [

"aws.codedeploy"

],

"detail-type": [

"CodeDeploy Deployment State-change Notification"

],

"detail": {

"state": [

"FAILURE"

]

}

}

Option D is incorrect: In this scenario, the Lambda function does not need an API gateway in order to be invoked by the CloudWatch Event rule.

The scenario described in the question involves automating the deployment of a Node.js application to Amazon EC2 instances using AWS CodeDeploy service, and sending a notification to a Slack channel when deployments fail. A DevOps engineer has configured a CloudWatch Event rule to achieve this.

The CloudWatch Event rule is responsible for detecting and responding to events that occur within the AWS environment. In this case, the rule is configured to detect CodeDeploy deployment events and send a notification to a Slack channel when deployments fail.

Option A suggests replacing the Lambda function with an SNS topic as the target of the CloudWatch Event rule. This would involve creating an HTTP endpoint to subscribe to the topic. While this approach may work, it would add unnecessary complexity to the solution, as it requires setting up an additional service (SNS) and endpoint.

Option B suggests removing the detail-type in the rule to capture all CodeDeploy events, and adding the logic in the Lambda function to determine the deployment failures and send notifications accordingly. This approach is more straightforward and efficient as it does not require setting up any additional services. It would involve modifying the Lambda function to handle all CodeDeploy events and check for deployment failures, then sending notifications to Slack accordingly.

Option C suggests modifying the detail-type to be "CodeDeploy Deployment State-change Notification” in the CloudWatch Event rule. This approach would ensure that the rule is only triggered when CodeDeploy deployment state-change events occur, which may not be sufficient for detecting deployment failures.

Option D suggests ensuring that the Lambda function has an API gateway to allow incoming API requests from events.amazonaws.com. While this is important for allowing the Lambda function to handle incoming events, it does not address the issue of detecting deployment failures and sending notifications to Slack.

Therefore, the best approach would be Option B, which involves modifying the Lambda function to handle all CodeDeploy events and checking for deployment failures before sending notifications to Slack. This would be the most straightforward and efficient approach, as it does not require setting up any additional services or endpoints.