Automating CodeCommit Change Notifications

Length: 00:14:52

Lesson Summary:

In this lesson, we'll demonstrate how to receive detailed email notifications about file changes and commit messages when a code update is pushed to CodeCommit. A code reviewer may subscribe to the SNS topic and recieve updates for any changes.

Create the CodeCommit Repository

aws codecommit create-repository --repository-name ChangeNotification

Note the cloneUrlHttp and Arn values in the response.

Create and Subscribe to the SNS Topic

aws sns create-topic --name CodeCommitChangeNotification

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:CodeCommitChangeNotification \
--protocol email \
--notification-endpoint my-email@example.com

Create an IAM Lambda Execution Role

  1. Add AWSLambdaBasicExecutionRole.
  2. Add the following policy: LambdaCodeCommitSnsPolicy.

     {
         "Version": "2012-10-17",
         "Statement": [{
             "Effect": "Allow",
             "Action": [
             "codecommit:*",
             "sns:*"
             ],
             "Resource": "*"
         }]
     }
    

Create the Lambda Function

  1. Name it "CodeCommitChangeNotification".

  2. Set the following environment variables:

    REPOSITORY_NAME = ChangeNotification

    SNS_TOPIC_ARN = arn:aws:sns:us-east-1:123456789012:CodeCommitChangeNotification

Create the CloudWatch Event Rule

This rule will detect branch or repository changes.

  1. Choose Event Pattern.
    • Service Name: CodeCommit
    • Event Type: CodeCommit Repository State Change
  2. Select Specific resource(s) by ARN, and enter the CodeCommit Repository ARN.
  3. Select the referenceCreated and referenceUpdated events.

    Event Pattern:

     {
     "source": [
         "aws.codecommit"
     ],
     "detail-type": [
         "CodeCommit Repository State Change"
     ],
     "resources": [
         "arn:aws:codecommit:us-east-1:123456789012:ChangeNotification"
     ]
     }
    
  4. Under Target, select the CodeCommitChangeNotification function.

Commit a Change

  1. Create and commit a file.
  2. Edit the file and commit it.

This lesson is only available to Linux Academy members.

Sign Up To View This Lesson

Or Log In

Looking For Team Training?

Learn More