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 describes a deployment automation process using AWS CodeDeploy service for a Node.js application. A DevOps engineer has configured a CloudWatch Event rule to send notifications to a Slack channel whenever a deployment fails. The options provided are potential solutions to address this requirement.

A. Replace the Lambda function with an SNS topic as the target of the CloudWatch Event rule. Create an HTTP endpoint to subscribe to the topic.

This option suggests replacing the Lambda function as the target of the CloudWatch Event rule with an SNS topic. The SNS topic can then have an HTTP endpoint subscribed to it, which would handle the notification to the Slack channel. This solution involves adding an additional step to the notification process and adds complexity.

B. Remove the detail-type in the rule in order to capture all CodeDeploy events. Add the logic in the Lambda function to determine the deployment failures and send notifications accordingly.

This option suggests removing the detail-type in the CloudWatch Event rule to capture all CodeDeploy events. The Lambda function would then be responsible for identifying and processing deployment failure events and sending notifications to the Slack channel. This solution requires additional coding and testing effort to ensure that the Lambda function identifies deployment failure events correctly.

C. Modify the detail-type to be "CodeDeploy Deployment State-change Notification” in the CloudWatch Event rule.

This option suggests modifying the detail-type in the CloudWatch Event rule to be "CodeDeploy Deployment State-change Notification." This modification allows the rule to capture only the CodeDeploy deployment state-change notifications. The Lambda function would then process only the relevant events, identify deployment failures, and send notifications to the Slack channel. This solution is simpler and more focused than the previous option and requires minimal coding effort.

D. Make sure that the Lambda function has an API gateway to allow the incoming API requests from events.amazonaws.com.

This option suggests adding an API gateway to the Lambda function to allow incoming API requests from events.amazonaws.com. This step is required to ensure that the Lambda function can receive the CloudWatch Event notifications. However, it does not address the requirement to send notifications to the Slack channel.

In summary, option C is the most appropriate solution as it is the simplest and most focused approach that requires minimal coding effort.