Question #632
A developer is configuring an Amazon EventBridge rule to trigger an AWS Lambda function whenever a new pull request is created or when an existing pull request's status changes (e.g., from open to closed). The Lambda function updates a monitoring dashboard with pull request statistics. The developer uses AWS CodeCommit for source control.
Which EventBridge event pattern will correctly invoke the Lambda function under these conditions?
{\n \"source\": [\"aws.codecommit\"],\n \"detail\": {\n \"event\": [\"pullRequestCreated\", \"pullRequestMergeStatusUpdated\"]\n }\n}
{\n \"source\": [\"aws.codecommit\"],\n \"detail\": {\n \"event\": [\"pullRequestCreated\", \"pullRequestStatusChanged\"]\n }\n}
{\n \"source\": [\"aws.codecommit\"],\n \"detail\": {\n \"event\": [\"pullRequestSourceBranchUpdated\", \"pullRequestStatusChanged\"]\n }\n}
{\n \"source\": [\"aws.codecommit\"],\n \"detail\": {\n \"event\": [\"pullRequestApprovalStateChanged\", \"pullRequestCreated\"]\n }\n}
Explanation
Answer B is correct because AWS CodeCommit sends specific events to EventBridge. The 'pullRequestCreated' event triggers when a new pull request is created, and 'pullRequestStatusChanged' fires when the status (e.g., open, closed) changes. These events align with the requirement to update the dashboard on creation or status changes.
Other options are incorrect:
- A: 'pullRequestMergeStatusUpdated' refers to mergeability status, not the PR's open/closed state.
- C: 'pullRequestSourceBranchUpdated' relates to branch updates, not status changes.
- D: 'pullRequestApprovalStateChanged' tracks approval status, not the PR's lifecycle status.
Key points: Use 'pullRequestCreated' and 'pullRequestStatusChanged' for PR creation and status transitions in EventBridge rules targeting CodeCommit events.
Answer
The correct answer is: B