By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Lambda Function Not Triggering on Merge Events for Specific Branches Using CloudWatch Event Pattern

0

Hello all,

I'm currently working on setting up a Lambda function to be triggered by merge events on the dev, release, and main branches of my CodeCommit repository. I've chosen to use CloudWatch (EventBridge) rules for this purpose. However, despite following the setup process as documented, my Lambda function does not seem to be triggered when merges occur into these branches.

Below is the event pattern I'm using in my CloudWatch rule:

{ "source": ["aws.codecommit"], "detail-type": ["CodeCommit Pull Request State Change"], "resources": ["arn:aws:codecommit:region:account-id:repository-name"], detail: { event: ["pullRequestMerged"], destinationReference: [ "refs/heads/release", "refs/heads/main", "refs/heads/develop", ], mergeOption: ["FAST_FORWARD_MERGE"], }, } I've double-checked the following:

  • The ARN for the repository is correct and matches the repository where the merges are occurring.
  • The Lambda function has the necessary permissions to be invoked by CloudWatch Events.
  • I've manually tested the Lambda function to ensure it works as expected when invoked directly.
  • Despite this, merges into dev, release, or main do not trigger the Lambda function.

Here are some additional details that might be relevant:

  • The merges are being done through the AWS CodeCommit console and via git command line, both with the same non-triggering result.
  • There are no errors in the CloudWatch Logs that indicate a problem with the rule or the Lambda function.

Questions:

  • Is the event pattern correctly configured to capture merge events on these specific branches?
  • Are there known issues or limitations with CloudWatch Events and CodeCommit integration that I might be overlooking?
  • Could there be a delay or configuration setting I'm missing that affects the triggering of the Lambda function?

Any advice, insights, or recommendations on how to troubleshoot and resolve this issue would be greatly appreciated.

Thank you in advance for your help!

1 Answer
1
Accepted Answer

Hello.

Looking at the document below, I thought there was no event called "pullRequestMerged".
https://docs.aws.amazon.com/codecommit/latest/userguide/monitoring-events.html

I thought that if I do the following, Lambda will run when a merge occurs.

{
  "source": ["aws.codecommit"],
  "detail-type": ["CodeCommit Repository State Change"],
  "resources": ["arn:aws:codecommit:region:account-id:repository-name"],
  "detail": {
    "event": ["referenceUpdated"],
    "referenceType": ["branch"],
    "referenceName": ["release", main, develop]
  }
}
profile picture
EXPERT
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago
  • This event is working for me. Thanks a lot!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions