Automating Notifications for CodeCommit Repository State Changes using AWS EventBridge and SNS

Automating Notifications for CodeCommit Repository State Changes using AWS EventBridge and SNS

ยท

3 min read

In the world of software development, collaboration and version control are paramount. AWS provides various services to facilitate these processes, and one such service is AWS CodeCommit, a fully-managed source control service. Often, developers need to be notified when certain actions occur in their repositories, such as when a merge or a pull request is merged into the main branch. In this blog post, we'll explore how to set up automated notifications using AWS EventBridge and Amazon SNS (Simple Notification Service) for CodeCommit repository state changes.

Architecture:

When a relevant event (such as a referenceCreated or referenceUpdated event for the master branch) occurs in the CodeCommit repository, it triggers the EventBridge rule. The rule then forwards the event to the configured SNS topic, which subsequently delivers notifications to the subscribed users or endpoints, informing them of the repository state change. This architecture enables automated and timely communication of important events in the software development lifecycle.

Prerequisites

Before we dive into the setup process, ensure that you have the following prerequisites:

  1. AWS Account: Access to an AWS account with permissions to create and manage AWS services.

  2. AWS CLI Installed: The AWS Command Line Interface (CLI) installed on your local machine.

  3. Access Keys: Access keys generated for an IAM user with CodeCommit, EventBridge, and SNS permissions.

Setup

1. Create User with Required Permissions:

and create access and Secret key

2. AWS Configuration

First, configure your AWS CLI with the access key credentials:

aws configure

Enter your Access Key ID and Secret Access Key when prompted.

2. Create an SNS Topic

Navigate to the Amazon SNS console and create a new topic. Subscribe your email address to the topic to receive notifications.

3. Create CodeCommit Repository

Create Git credentials

Copy the clone url of the repository

Git clone in local

Add files and push into repository

Check git codecommit

4. Create an EventBridge Rule

Next, create an EventBridge rule that triggers when a specific CodeCommit repository state change occurs:

  • Event Pattern I used:
{
  "source": ["aws.codecommit"],
  "detail-type": ["CodeCommit Repository State Change"],
  "resources": ["arn:aws:codecommit:region:ACC Number:Repository name"],
  "detail": {
    "event": ["referenceCreated", "referenceUpdated"],
    "referenceType": ["branch"],
    "referenceName": ["master"]
  }
}

Replace region, ACC Number, and Repository name with the appropriate values.

  • Target: Select the SNS topic you created earlier.

4. Testing

To test the setup, make a commit to the master branch of your CodeCommit repository. You should receive a notification via email indicating the repository state change.

Conclusion

Automating notifications for CodeCommit repository state changes is essential for keeping your team informed and facilitating efficient collaboration. By leveraging AWS EventBridge and SNS, you can seamlessly integrate these notifications into your development workflow, ensuring that everyone stays up-to-date with the latest changes.

In this blog post, we've covered the setup process step-by-step, allowing you to implement this functionality in your AWS environment with ease. With automated notifications in place, you can focus more on building great software and less on manually tracking repository changes.

Did you find this article valuable?

Support Navya A by becoming a sponsor. Any amount is appreciated!

ย