DOP-C02 Question 241
Single answerYour organization is using AWS CodePipeline to automate the release process for a web application. As part of the deployment pipeline, you need to ensure that the application passes automated functional tests before it is deployed to the production environment. These tests should only run when changes are pushed to the 'main' branch of the source repository. Which solution will best meet this requirement?
- A
Use CodePipeline with a source stage configured to trigger on changes to the 'main' branch, followed by a test stage that executes the functional tests.
- B
Configure a CloudWatch Events rule to trigger the functional tests whenever an AWS CodeCommit push occurs, regardless of the branch.
- C
Use AWS CodeDeploy directly to run the functional tests before deploying the application to the production environment.
- D
Use CodePipeline with a condition in the test stage that validates whether the source branch is 'main' before running the tests.
Show answer and explanation
Correct answer: A
Explanation
The best solution for ensuring functional tests run only on changes to the 'main' branch is to configure AWS CodePipeline with a source stage that triggers on changes to the 'main' branch. This approach integrates seamlessly with the pipeline and ensures that functional tests are executed before deployment to production. Other options either lack the necessary branch filtering or misapply the purpose of AWS services.
- A. Correct.
This is the correct solution. CodePipeline can be configured to trigger based on changes to a specific branch, such as 'main'. Functional tests can then be added as a dedicated stage in the pipeline to ensure that changes are validated before deployment.
- B. Incorrect.
This is incorrect because triggering functional tests through a CloudWatch Events rule would not allow you to restrict the tests to only changes on the 'main' branch.
- C. Incorrect.
This is incorrect as AWS CodeDeploy is primarily used for deploying applications and does not natively handle functional test execution as part of a deployment pipeline.
- D. Incorrect.
This is incorrect because CodePipeline does not support conditional logic directly within stages. Conditions like branch validation should be handled in the source stage configuration.