AWS Certified Developer – Associate — Question 397
A software company is using AWS CodeBuild to build an application. The buildspec runs the application build and creates a Docker image that contains the application. The company needs to push the Docker image to Amazon Elastic Container Registry (Amazon ECR) only upon the completion of each successful build.
Which solution meets these requirements?
Answer options
- A. Change the buildspec by adding a post_build phase that uses the commands block to push the Docker image.
- B. Change the buildspec by adding a post_build phase that uses the finally block to push the Docker image.
- C. Specify the Docker image in the buildspec's artifacts sequence with an action to push the image.
- D. Use a batch build to define a build matrix. Use the batch build to push the Docker image.
Correct answer: A
Explanation
In AWS CodeBuild, the commands specified in the 'commands' block of a phase (like post_build) will only run if the preceding build phases succeeded. Conversely, commands in a 'finally' block execute regardless of build success or failure, which does not meet the requirement to push only upon successful builds. Using the artifacts sequence or a batch build matrix are incorrect methods for pushing Docker images to Amazon ECR.