Accelerate Your EC2 Restarts with AWS CodeDeploy's RESTART Mode
In a fast-paced production environment, downtime can be costly. AWS CodeDeploy's RESTART deployment mode exists to minimize this downtime by allowing you to restart your fleets without losing the benefits of CodeDeploy's management features. This mode keeps your deployment within CodeDeploy's ecosystem, ensuring that batch sizing, health checks, alarm monitoring, and rollback behavior are all maintained during the process.
To use RESTART mode, simply set the deploymentMode to RESTART in the CreateDeployment API call and provide no revision. CodeDeploy will automatically resolve the last successful revision for the deployment group and create a deployment record. Each host will follow a specific sequence: ApplicationStop, DownloadBundle, BeforeInstall, Install, AfterInstall, ApplicationStart, and ValidateService. This structured approach helps ensure that your application is restarted cleanly and efficiently.
In practice, you need to be aware of a few important details. Ensure that you are using CodeDeploy agent version 2.1.0 or newer on your target hosts to take advantage of local revision reuse. Be cautious with rollbacks; they cannot reverse external configuration changes, so you must fix those issues before retrying. If an alarm is already in an ALARM state, the CreateDeployment command will still execute, but CodeDeploy will halt the deployment once it detects the alarm during polling. This could lead to confusion if you're not monitoring your alarms closely.
Key takeaways
- →Set deploymentMode to RESTART in the CreateDeployment API to initiate a restart.
- →Utilize the sequence of operations: ApplicationStop, DownloadBundle, BeforeInstall, Install, AfterInstall, ApplicationStart, and ValidateService.
- →Ensure CodeDeploy agent version 2.1.0 or newer is installed on target hosts for optimal performance.
- →Monitor alarms closely, as existing alarms can halt deployments even after initiation.
- →Remember that rollbacks won't fix external configuration issues; address those first.
Why it matters
In production, reducing downtime during application restarts is crucial. RESTART mode allows for quick, controlled restarts, minimizing service disruption and maintaining application availability.
Code examples
aws deploy create-deployment \
--application-name MyApp \
--deployment-group-name MyDeploymentGroup \
--deployment-mode RESTART \
--description "Restart processes after a runtime configuration update"1aws deploy create-deployment \
2 --application-name MyApp \
3 --deployment-group-name MyDeploymentGroup \
4 --deployment-mode RESTART \
5 --deployment-config-name CodeDeployDefault.OneAtATime \
6 --description "Restart one host at a time"aws deploy get-deployment --deployment-id d-EXAMPLE123When NOT to use this
RESTART mode does not execute the load balancer BlockTraffic and AllowTraffic steps, meaning the host remains registered while its application stops and starts. If your application requires strict traffic control during restarts, consider using a different deployment strategy.
Want the complete reference?
Read official docsSimple, affordable cloud — VMs, Kubernetes, and managed databases in minutes. Trusted by 600,000+ developers. Spin up a Droplet in 60 seconds.
Try DigitalOcean →Unlocking Cost Efficiency with Amazon EC2 T8i Instances
Amazon's new T8i instances offer a low-cost solution for workloads with low-to-moderate CPU utilization. Powered by Intel's sixth generation Xeon processors, these instances leverage a CPU credit system to optimize performance and cost.
Unlocking Performance: Amazon EC2 R9g and R9gd Instances with Graviton5 Processors
Amazon EC2's R9g and R9gd instances are here, powered by the new Graviton5 processors, delivering a significant performance boost. With up to 25% better compute performance compared to their predecessors, these instances are designed for memory-intensive workloads that demand speed and efficiency.
Celebrating 20 Years of Amazon EC2: The Backbone of Cloud Computing
Amazon EC2 revolutionized cloud computing by providing scalable and highly available infrastructure. With features like Elastic Load Balancing and Auto Scaling, it addresses the challenges of modern application deployment.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.