CodeDeploy EC2 in-place deployments
Exam alignment: DOP-C02 Domain 1 task statements for pipelines, testing, artifacts, or deployment.
Learning objective
Use AppSpec hooks, agents, healthy-host settings, and rollback for existing instances.
| Difficulty / Schwierigkeitsgrad | Intermediate |
| Study time / Lernzeit | 120 minutes |
| Prerequisites / Voraussetzungen | Previous lessons in this volume |
Professional scenario
A fleet accepts reduced capacity during release but needs automated host updates.
Core concepts
- In-place modifies current target instances.
- The CodeDeploy agent executes AppSpec lifecycle hooks.
- Deployment configuration controls minimum healthy hosts.
- Load balancer integration removes hosts during update.
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 |
|---|---|---|
| Limited duplicate capacity | In-place | Uses current fleet |
| Availability control | Minimum healthy hosts | Controls concurrency |
| Validation | ValidateService plus alarm | Host and runtime evidence |
Failure modes and troubleshooting
- Agent missing or offline.
- Instance profile cannot read revision.
- Hook script returns non-zero.
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: Deploy a small revision and trigger one hook failure.
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
- Choosing in-place for strict immediate rollback.
- Impossible healthy-host percentage for small fleet.
Key takeaways
- In-place modifies current target instances.
- Load balancer integration removes hosts during update.
- 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.