Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

CI/CD concepts

CI/CD concepts for AWS: definitions, pipeline components, deployment strategies, AWS tooling (CodeCommit/CodeBuild/CodePipeline/CodeDeploy), examples and exam-focused notes.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

CI/CD helps engineers deliver software changes faster and with fewer errors. In AWS cloud application engineering, CI/CD automates building, testing and deploying code so teams can push features and fixes to production reliably and repeatably.

Key ideas

Start with clear definitions (each bold term is defined before use):

  • Continuous Integration (CI) — the practice of frequently merging developers' code changes into a shared repository and automatically building and testing each merge. Assumes a shared VCS (version control system) and automated build/test tools. The goal is to detect integration problems early.

  • Continuous Delivery (CD) — the practice of keeping codebase in a deployable state so that any validated change can be released to production on demand. Assumes automated tests and automated build artifacts; manual approval may be required for production releases.

  • Continuous Deployment (also CD) — an extension of Continuous Delivery where every validated change that passes automated tests is automatically deployed to production without human intervention. Assumes high confidence in automated tests and monitoring.

  • Pipeline — an automated sequence of stages (for example: source, build, test, staging, deploy) that transform and move code or artifacts from a repository to production. Each stage has inputs (artifacts) and outputs (artifacts, status).

  • Artifact — a file or set of files created by the build stage (for example a JAR, Docker image, zip bundle). Artifacts are immutable inputs to later stages.

  • Stage — a logical step in a pipeline (source, build, test, deploy). Each stage may run in parallel or serially depending on pipeline configuration.

  • Action — a concrete operation inside a stage (for example: run unit tests, push Docker image, run migration script).

  • Idempotency — an operation property where executing it multiple times has the same effect as executing it once. Important in deployment scripts to safely retry failed steps.

  • Blue/Green deployment — a deployment strategy where a new environment ('green') is prepared alongside the currently running environment ('blue'). After verification, traffic switches from blue to green. Useful for near-zero-downtime and quick rollback.

  • Canary deployment — a strategy that rolls new code to a small subset of users or servers first, monitors behaviour, then gradually increases traffic until full rollout.

  • Rolling deployment — a strategy that updates servers in small batches, replacing instances of the old version with the new version over time.

  • Pipeline as Code — storing pipeline definitions (configuration) in version control (for example buildspec.yml, appspec.yml, or CloudFormation templates for CodePipeline). It makes pipelines reproducible and reviewable.

  • Immutability of artifacts — once an artifact is created for a pipeline run, it should not be changed. This allows reproducible deployments and easier rollback.

  • Shift-left testing — move testing earlier into the pipeline (unit tests, static analysis) so problems are detected sooner and cheaper to fix.

  • Secrets handling — do not store secrets in repo or plain buildspec; use AWS Secrets Manager, Parameter Store, or encrypted environment variables. Assumes appropriate IAM permissions.

AWS-specific components (short):

  • AWS CodeCommit — a managed git-compatible repository service.
  • AWS CodeBuild — a managed build service that runs buildspec scripts to compile, test and produce artifacts.
  • AWS CodePipeline — an orchestration service that wires source, build, test and deploy actions into a pipeline.
  • AWS CodeDeploy — a deployment service that supports EC2/On-Premises and Lambda/Serverless/ ECS deployments, and supports blue/green, canary and rolling strategies.

For diagrams (exam drawing): draw a left-to-right pipeline diagram: left box labeled 'Source (CodeCommit/GitHub)', arrow to 'Build (CodeBuild)' box, arrow to 'Test (Unit/Integration)', arrow to 'Deploy (CodeDeploy / ECS / Lambda)'. Label artifacts between build and test with 'artifact (immutable)'. For blue/green, draw two boxes 'Blue (prod)' and 'Green (new)', show traffic router (Elastic Load Balancer or Route 53) switching from Blue to Green.

Assumptions behind CI/CD: reliable VCS, automated builds/tests, observability for production, and IAM for secure cross-service operations. If any assumption fails (e.g., no automated tests), CI/CD provides less safety.

Formulas

For programming/CI/CD topics, list the syntax to remember:

git add . — stage all changes for commit

git commit -m 'message' — commit changes locally

git push origin main — push commits to remote branch 'main'

buildspec.yml structure (remember keys): version: 0.2 — top line phases: install: pre_build: build: post_build: artifacts: files:

appspec.yml top keys for CodeDeploy (EC2/OnPrem): version: 0.0 os: linux files: hooks: ApplicationStop: BeforeInstall: AfterInstall: ApplicationStart: ValidateService:

aws codepipeline start-pipeline-execution --name MyPipeline — start pipeline via AWS CLI

aws codebuild start-build --project-name MyProject — start build via AWS CLI

ECS task definition JSON is registered before aws ecs update-service to deploy updated image.

Note: always specify IAM role ARNs for services to assume; in CodeBuild use serviceRole field; in CodePipeline give action roles or role per pipeline.

Worked examples

Example 1 — Step-by-step pipeline trace for a small web app (exam-style step tracing): Given: 4 EC2 instances behind an ALB; deployment uses rolling updates with batch size 2.

Steps:

  1. Developer A commits and pushes code to CodeCommit branch 'main'. (Action: Source triggers CodePipeline.)
  2. CodePipeline starts and passes source artifact (commit id + zip) to CodeBuild. (Action: Build phase: CodeBuild runs buildspec.yml.)
  3. Build produces artifact myapp-v1.1.zip and uploads to S3 with object key artifacts/myapp-v1.1.zip (immutable). CodeBuild exits with success.
  4. Pipeline moves to Deploy stage; CodeDeploy configured for EC2 rolling with batch size 2. It takes artifact and runs hooks on first batch (instances 1 and 2): stop old app, install new files, start app, run health check.
  5. If health check passes for batch 1, CodeDeploy proceeds to batch 2 (instances 3 and 4). If any batch health check fails, CodeDeploy stops and rolls back (or triggers rollback hook depending on config).

Final: After successful window on both batches, all instances run the new version. To draw this, show EC2 instances in two groups with arrows showing sequential update.

Example 2 — Canary deployment math (numerical): Scenario: 1000 users, canary plan 10% then 100% after verification. You shift 10% traffic first.

Steps:

  • Initial traffic to new version = 0.
  • After canary step 1: new version gets 10% of 1000 = 100 users.
  • Monitor for errors for agreed observation window (for example 15 minutes). If error rate acceptable, shift 90% more: final 100% -> new version gets 1000 users.

If error rate rises above threshold (e.g., error_rate > 0.5%), abort and rollback; rollback returns 100% traffic to previous stable version. Document thresholds in pipeline configuration.

Example 3 — Debugging a failed build (algorithmic step-by-step): Given: Build fails at 'install' phase for missing dependency.

Steps to trace and fix (what exam expects):

  1. Open CodeBuild build logs via console or aws codebuild batch-get-builds and inspect last lines for error messages.
  2. If missing package X, edit buildspec.yml under install: to run pip install X or add package to Docker base image.
  3. Commit change, push to repo, pipeline triggers, build runs again; verify green.
  4. If failure persists, check IAM role permissions for CodeBuild to access S3 or Secrets Manager, and update role policies.

Show clear action and verification steps; include that idempotent install steps help safe retries.

Common mistakes

  • Putting secrets in source code or buildspec files.
  • Not giving the pipeline least-privilege IAM roles; using overly broad roles (for example wildcard '*') is insecure.
  • Forgetting to add health checks that allow automatic rollback decisions.
  • Assuming zero downtime automatically — the deployment strategy chosen (rolling vs blue/green) affects downtime.
  • Not storing pipeline configuration in version control (no pipeline-as-code).
  • Relying only on unit tests and skipping integration/end-to-end tests in the pipeline.

For your exam

Typical question types:

  • Definitions and short notes: define CI, CD, pipeline, artifact, blue/green, canary. A full answer states the definition, assumptions and one sentence on purpose and example.
  • Diagram question: draw a pipeline with Source, Build, Test, Deploy. Label artifact storage and rollback path. A full-marks answer includes arrows, labels, and a note on where secrets and IAM roles are needed.
  • Long/essay: Explain CI/CD pipeline design for an AWS-hosted microservice. Full answer discusses CodeCommit/CodeBuild/CodeDeploy or alternatives, pipeline stages, artifacts, test strategy (unit/integration), deployment strategies and rollback plan, monitoring, and security (IAM, Secrets Manager).
  • Short program/config: write a minimal buildspec.yml that installs dependencies, runs tests and produces artifacts. Full answer has correct YAML keys and explains artifact path.
  • Troubleshooting/analytical: given a failed deployment trace, list steps to find root cause and fix. Full answer lists log access, typical causes, and remediation steps.

What to include for full marks: clear definitions, correct diagram labels, mention artifacts and immutability, mention IAM and secrets handling, describe one or more deployment strategies and when to use them, and mention monitoring/rollback.

Quick check

  1. Define Continuous Integration in one sentence.
  2. Name two deployment strategies supported by CodeDeploy.
  3. Where should secrets for pipeline builds be stored in AWS (name one service)?

Answers: 1) Continuous Integration is the practice of frequently merging code into a shared repository and automatically building and testing each merge. 2) Blue/Green and Canary (also Rolling). 3) AWS Secrets Manager (or AWS Systems Manager Parameter Store).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?