Create a Notification for Deleted Branches in CodeCommit | AWS Administrator Guide

Implementing CodeCommit Trigger for Branch Deletion Notifications

Prev Question Next Question

Question

You are an AWS administrator.

Last week, a new employee accidentally deleted a repository branch in CodeCommit.

For certain key repositories, you are told to create a notification when someone deletes any branch in CodeCommit.

You plan to configure a trigger in CodeCommit.

Which service should you use to implement this in the best way?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - C.

For a CodeCommit repository, you can configure triggers so that code pushes or other events can trigger actions.

The supported trigger services are SNS and Lambda.

You can create up to 10 triggers for each CodeCommit repository:

Option A is incorrect: Although the Lambda function potentially works, it brings unnecessary work to interact with SES.

For this case, the best way is to use SNS.

Option B is incorrect: Because the CodeCommit trigger service does not support SQS.

Option C is CORRECT: Because SNS is the easiest and straightforward method.

Users need to subscribe to the SNS topic and get notified.

Option D is incorrect: Same reason as Option.

B.

Resources:

GetHelloWorld:
Type: AWS: :Serverless: : Function
Properties:
Handler: index.get
Runtime: nodejs8.10
Role:
Fn::GetAtt:
- LambdaExecutionRole
- Arn
Events:
GetEvent:
Type: Api
Properties:
Path: /
Method: get
LambdaExecutionRole:
Description: Creating service role in IAM for AWS Lambda
Type: AWS: :IAM::Role
Properties:
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}'

The correct answer to this question is C. For the repository event of deleting branches, create a trigger in CodeCommit to an Amazon SNS topic to provide notifications to users.

CodeCommit is a managed source control service provided by AWS that allows developers to store, manage, and version control their code. CodeCommit provides a number of event types that can be used to trigger actions or notifications. In this scenario, we need to create a notification when a branch is deleted in CodeCommit, so we need to use a trigger that is fired when this event occurs.

Option A suggests using a Lambda function with Simple Email Service (SES) to send emails to notify users. While this is a valid approach, it is not the best option for this scenario because SES is primarily designed for sending transactional emails, not notifications. In addition, this option involves creating and maintaining a custom Lambda function, which adds complexity to the solution.

Option B suggests using an Amazon Simple Queue Service (SQS) queue to provide warnings to users. This option could work, but it does not provide a notification to users in real-time when the branch is deleted. Instead, the warning would be placed in a queue and users would need to check the queue to see if a warning was issued. This is not an optimal solution for a scenario where timely notifications are required.

Option C suggests using an Amazon SNS topic to provide notifications to users. This is the best option for this scenario because SNS is designed specifically for sending notifications in real-time. When a branch is deleted in CodeCommit, a trigger can be fired that sends a message to an SNS topic, which in turn sends a notification to subscribers. Subscribers can receive notifications via email, SMS, mobile push notifications, or other supported protocols. This option is easy to configure and maintain and provides timely notifications to users.

Option D suggests using an AWS CloudWatch Event to provide warnings. While CloudWatch Events can be used to trigger actions or notifications, they are primarily designed for monitoring and responding to events across AWS services. This option adds unnecessary complexity to the solution and is not the best option for this scenario.

In summary, option C is the best option for this scenario. We should use an SNS topic to provide notifications to users when a branch is deleted in CodeCommit.