'How to create an AWS Cloudwatch event that runs Codebuild when a pull request is created in CodeCommit?

I want to create a Cloudwatch event that runs a Codebuild project every time a pull request is made on a CodeCommit branch. However, the event I made is not triggering upon creation of the pull request on the master branch. Hope you guys could give me some advice on this.

Below is the event pattern of the event rule that I made:

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit Pull Request State Change"
  ],
  "resources": [
    "arn:aws:codecommit:XX-XX-1:XXX:dev-test"
  ],
  "detail": {
    "event": [
      "pullRequestCreated"
    ],
    "referenceType": [
      "branch"
    ],
    "referenceName": [
      "master"
    ]
  }
}


Solution 1:[1]

Your event does not look right to me. I would try using:

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit Pull Request State Change"
  ],
  "detail": {
    "event": [
      "pullRequestCreated"
    ],
    "repositoryNames": [
      "<your-repo>"
    ]
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1