Which solution will meet these requirements?
Create a CodeBuild project to run the unit and integration tests. Create a CodeCommit approval rule template. Configure the template to require the successful invocation of the CodeBuild project. Attach the approval rule to the project’s CodeCommit repository.
Create an Amazon EventBridge (Amazon CloudWatch Events) rule to match pullRequestCreated events from CodeCommit. Create a CodeBuild project to run the unit and integration tests. Configure the CodeBuild project as a target of the EventBridge (CloudWatch Events) rule that includes a custom event payload with the CodeCommit repository and branch information from the event.
Create an Amazon EventBridge (Amazon CloudWatch Events) rule to match pullRequestCreated events from CodeCommit. Modify the existing CodePipeline pipeline to not run the deploy steps if the build is started from a pull request. Configure the EventBridge (CloudWatch Events) rule to run the pipeline with a custom payload that contains the CodeCommit repository and branch information from the event.
Create a CodeBuild project to run the unit and integration tests. Create a CodeCommit notification rule that matches when a pull request is created or updated. Configure the notification rule to invoke the CodeBuild project.
Explanations:
This option suggests creating a CodeCommit approval rule template that requires a successful invocation of a CodeBuild project. However, CodeCommit approval rules cannot directly invoke CodeBuild projects. Approval rules are used to enforce manual approval before merging, not to run automated tests prior to merge.
This option creates an EventBridge rule that listens forpullRequestCreatedevents from CodeCommit and triggers a CodeBuild project to run unit and integration tests. This ensures tests are executed on every pull request before merging, effectively preventing the pipeline from being blocked by failing tests.
This option involves modifying the existing CodePipeline to skip deploy steps for pull requests, which does not directly address the requirement of running tests before merging. While it might prevent deployment of broken code, it does not ensure tests are run on each pull request, which is the primary goal.
Although this option suggests creating a CodeBuild project triggered by a notification rule when a pull request is created or updated, it does not directly integrate with the pull request process for testing before merging. CodeCommit notifications do not run the tests in a controlled manner that can block the merge based on results.