2.3.2. AWS CodeBuild for Builds & Tests
First Principle: AWS CodeBuild provides a scalable, on-demand build environment for developers, automating the compilation, testing, and packaging of application code within CI/CD pipelines.
CodeBuild compiles your code, runs tests, and produces deployment artifacts, all defined in buildspec.yml ā a YAML file in your repo root that specifies what happens during the build.
The build runs in four phases: install (dependencies), pre_build (setup like ECR login), build (compile and run unit tests), and post_build (package artifacts, notifications). The exam frequently asks which phase handles which task ā unit tests run in build, not a separate step.
CodeBuild runs in managed Docker containers with pre-configured runtimes, or you provide a custom image. Outputs go to S3 as artifacts that CodeDeploy picks up for deployment. Enable dependency caching to avoid re-downloading npm modules or Maven repos on every build.
Scenario: You need to automate the process of compiling your application's source code, running unit tests, and packaging the output into a deployable artifact (e.g., a .zip file or a Docker image) as part of your CI pipeline.
ā ļø Exam Trap: CodeBuild uses a buildspec.yml file ā not buildspec.yaml, not build.yml. If this file is missing or misconfigured, the build fails immediately. The exam tests whether you know the correct filename and structure.
