A developer needs to deploy a new feature to an existing application running on Amazon EC2 instances managed by an Auto Scaling Group. The deployment must ensure zero downtime and provide an easy rollback mechanism if issues are detected. The new feature requires a database schema change that must be applied before the new application version receives traffic. Which AWS CodeDeploy deployment type and configuration would best meet these requirements?
- AIn-place deployment with a `BeforeInstall` hook for schema changes.
- BAll-at-once deployment with a `ApplicationStop` hook for schema changes.
- CLinear deployment with a Lambda function to apply schema changes between increments.
- DBlue/Green deployment with a `BeforeAllowTraffic` hook for schema changes.
Show answer & explanationAnswer & explanation
Correct answer: D. Blue/Green deployment with a `BeforeAllowTraffic` hook for schema changes.
Blue/Green deployment in CodeDeploy creates a completely new set of instances (green environment), deploys the new application, and allows for pre-traffic hooks (`BeforeAllowTraffic`) to run database schema changes on the new environment before traffic is cut over. This ensures zero downtime and provides an automatic rollback to the old (blue) environment if issues arise during or after the traffic shift.
Why the other options are wrong
- A. In-place deployment updates instances one by one or in batches, which can lead to downtime if not carefully managed. `BeforeInstall` runs too early, before the new application code is fully deployed, and doesn't provide a clean rollback to the old environment.
- B. All-at-once deployment leads to downtime as all instances are updated simultaneously. `ApplicationStop` hook runs when the old application is stopping, which is not suitable for applying schema changes for the *new* application version.
- C. Linear deployment is a type of in-place deployment and doesn't achieve zero downtime or a clean rollback to an entirely separate old environment. Using Lambda for schema changes would require complex custom logic for rollback.
CodeDeploy Blue/Green with Pre-Traffic Hooks
A CodeDeploy strategy for EC2/Auto Scaling Groups that creates a new environment, deploys the application, and uses pre-traffic hooks (like `BeforeAllowTraffic`) to run tasks like database migrations on the new environment before traffic is shifted, ensuring zero-downtime and easy rollback.
- Zero-downtime deployments.
- New environment created (green).
- Pre-traffic hooks for migrations.
- Automatic rollback to old environment (blue).
Memory trick: BLUE-GREEN: Build Logic Under Every Goal, Right, Even New.