EC2 blue/green immutable replacement
Exam alignment: DOP-C02 Domain 1 task statements for pipelines, testing, artifacts, or deployment.
Learning objective
Validate a replacement environment, shift traffic, and retain the old fleet for rollback.
| Difficulty / Schwierigkeitsgrad | Intermediate |
| Study time / Lernzeit | 120 minutes |
| Prerequisites / Voraussetzungen | Previous lessons in this volume |
Professional scenario
A customer-facing service cannot tolerate mixed versions or long rollback.
Core concepts
- Blue/green runs original and replacement environments.
- Green is validated before production traffic.
- Load balancers support controlled traffic routing.
- Database changes must be backward compatible during overlap.
Architecture flow
- Identify the release input and immutable identity.
- Select the managed AWS control plane and least-privilege role.
- Execute build, test, artifact, or deployment work.
- Collect service events, logs, reports, and runtime metrics.
- Stop, retry, or roll back according to explicit rules.
Decision matrix
| Requirement | Preferred choice | Reason |
|---|---|---|
| Fast rollback | Retain blue temporarily | Traffic can return |
| No mixed host state | Immutable replacement | Consistent instances |
| Breaking schema change | Expand-and-contract | Supports both versions |
Failure modes and troubleshooting
- Green fails target health.
- Business transaction fails despite technical health.
- Blue is terminated too early.
Security and operations
- Use short-lived service roles and least privilege.
- Encrypt artifacts and protect logs from secret exposure.
- Record changes and approvals for audit.
Hands-on lab
Goal / Ziel: Design blue/green with health, business checks, and rollback window.
Tasks
- Create the smallest safe test architecture.
- Implement or simulate the main workflow.
- Introduce one controlled failure.
- Diagnose it from service evidence.
- Document cleanup and one improvement.
Validation
- The workflow uses an immutable version.
- A required failure blocks promotion.
- The diagnosis identifies the first failed transition.
Cost control / Kostenkontrolle: Keep resources short lived; read cleanup before starting.
Cleanup
- Delete pipeline/build/deployment resources.
- Delete temporary artifacts, images, logs, and roles.
Exam traps
- Ignoring database compatibility.
- Assuming ALB health proves business success.
Key takeaways
- Blue/green runs original and replacement environments.
- Database changes must be backward compatible during overlap.
- Decisions must be justified by requirements and failure behavior.
Review questions
- What is the immutable release identity?
- Which evidence proves failure or success?
- What is the safest recovery action?
Answers
- A version, digest, or uniquely versioned artifact.
- Service events, logs, reports, health checks, and runtime metrics.
- Restore the known-good version using the configured rollback path.