Courseiva
SDLC AutomationhardMultiple ChoiceObjective-mapped

DOP-C02 SDLC Automation Practice Question

A company uses AWS CodePipeline with a GitHub source action. They want to automatically start the pipeline when a pull request is merged to the main branch. However, the pipeline also starts on every push to any branch. How can they limit the pipeline to only trigger on push events to the main branch?

⚠ Common exam trap

Watch out — candidates often think branch filtering must be done inside the pipeline stages (Option D) or via a custom Lambda (Options A and B), overlooking CodePipeline's native webhook branch filter configuration that prevents the pipeline from even starting on non-matching branches.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Configure the source action's 'Branch' field to 'main' and set 'PollForSourceChanges' to false, and use a webhook with filters.

It configures the source action to only respond to push events on the main branch by setting the 'Branch' field to 'main' and disabling polling ('PollForSourceChanges': false), while using a webhook with branch filters. This ensures that only pushes to the main branch trigger the pipeline, not pushes to any other branch.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use a Lambda function as a source action instead of GitHub.

    Why it's wrong here

    Using a custom Lambda function as the source action instead of a GitHub source action is unnecessarily complex. CodePipeline natively supports GitHub sources with automatic webhook integration and branch filtering, so a Lambda would have to duplicate that logic—fetching commit metadata, invoking StartPipelineExecution, and handling errors—without adding value. It also introduces extra Lambda invocation costs and additional failure points, and it loses the built-in change metadata visible in the pipeline console.

  • Create a GitHub webhook manually and point it to a Lambda function that starts the pipeline only for main branch pushes.

    Why it's wrong here

    Creating a manual GitHub webhook and pointing it at a Lambda function to start the pipeline only for main-branch pushes is an anti-pattern because CodePipeline already manages that webhook automatically when you configure a GitHub source action with source code change detection enabled. A manual webhook requires you to validate GitHub signatures, filter push events, and ensure idempotent StartPipelineExecution calls, which is fragile and redundant. Any misconfiguration could cause missed or duplicate pipeline runs, whereas the managed webhook enforces the branch filter at the platform level.

  • Configure the source action's 'Branch' field to 'main' and set 'PollForSourceChanges' to false, and use a webhook with filters.

    Why this is correct

    This is the correct approach. Setting the source action's Branch field to 'main' and disabling PollForSourceChanges ensures that the pipeline uses the CodePipeline-managed GitHub webhook instead of legacy polling, preventing duplicate executions. The webhook is configured with event filters that only forward push events for refs/heads/main, so the pipeline starts only when the default/main branch is updated. This gives you native, real-time triggering without custom code and without starting pipelines for other branches.

  • Add a condition in the pipeline's first stage to check the branch name.

    Why it's wrong here

    Adding a condition in the first stage is not a valid mechanism to prevent the pipeline from being triggered by commits to non-main branches. A pipeline execution is already created and the source action runs before any stage condition evaluates, so a condition will only cause the stage to fail after the fact—it does not stop the trigger. Conditions are designed to gate stage transitions based on criteria like variables or manual approvals, not to act as a branch filter for incoming source events.

About these practice questions

Courseiva writes every DOP-C02 question from scratch — 251 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.