Choosing an Elastic Beanstalk Deployment Policy
This lesson explains how Elastic Beanstalk deployment policies trade deployment speed and cost against capacity, downtime and rollback speed. Choosing the right policy for a requirement is a classic exam question.
Learning outcomes
After completing this lesson, you will be able to:
- Compare the all at once, rolling, rolling with additional batch, immutable and traffic-splitting policies.
- Describe how blue/green deployments use a CNAME swap outside the deployment policies.
- Explain why production databases should be created outside an Elastic Beanstalk environment.
Comparing the policies
An Elastic Beanstalk deployment policy decides how a new application version reaches the environment's instances. The policies trade speed and cost against downtime, capacity and how quickly a failed deployment can be undone.
All at once deploys the new version to every instance at the same time. It is the fastest policy, but the application is unavailable while the instances update, and a faulty version breaks every instance, so it suits development environments. Rolling updates the instances in batches, taking each batch out of service while it updates. There is no downtime, but capacity is reduced by one batch throughout, and old and new versions serve traffic side by side until the deployment finishes. Rolling with additional batch first launches an extra batch of instances, so full capacity is kept throughout, at the cost of the extra instances during the deployment. With either rolling policy, undoing a failure means another rolling deployment of the old version.
Immutable launches a complete set of new instances, running the new version, in a temporary Auto Scaling group. Only when they pass health checks are they moved into the original group and the old instances terminated. A failure affects only the new instances, which are simply terminated, so rollback is fast and safe, but the deployment takes longer and briefly doubles the number of instances. Traffic splitting works in the same way, but sends only a chosen percentage of client traffic to the new instances for an evaluation period, a canary test with real users, and rolls back automatically if their health deteriorates. The following table summarises the policies.
| Policy | How it works | Downtime | Capacity during deploy | Rollback |
|---|---|---|---|---|
| All at once | Deploys to every instance together | Yes | None while deploying | Redeploy the old version |
| Rolling | Updates instances in batches | No | Reduced by one batch | Another rolling deployment |
| Rolling with additional batch | Launches an extra batch first, then rolls | No | Full | Another rolling deployment |
| Immutable | Deploys to new instances in a temporary Auto Scaling group, then moves them into the original group | No | Full (doubles briefly) | Fast: terminate the new instances |
| Traffic splitting | Sends a percentage of traffic to new instances for an evaluation period (canary) | No | Full (doubles briefly) | Fast: shift traffic back |
Example. Ten instances must keep full capacity and roll back quickly. Immutable fits best: it starts ten new instances and rolls back by terminating them.
Configuring a policy
The policy and batch size are set in the aws:elasticbeanstalk:command namespace; traffic splitting has its own namespace for the percentage and evaluation time.
# .ebextensions/deploy.config
option_settings:
aws:elasticbeanstalk:command:
DeploymentPolicy: TrafficSplitting
aws:elasticbeanstalk:trafficsplitting:
NewVersionPercent: "10"
EvaluationTime: "15" # minutesThe example above configures a traffic-splitting deployment. The following list describes further settings and behaviour of deployment policies.
BatchSizeType(PercentageorFixed) andBatchSizecontrol rolling batches.- Immutable and traffic splitting deployments require a load-balanced environment.
- A failed immutable or traffic-splitting deployment leaves the existing instances untouched.
Blue/green deployments
Blue/green is performed outside the deployment policies: deploy the new version to a separate environment, test it, then swap the environment URLs (a CNAME swap). Rollback is a second swap. Blue/green suits major changes, such as a new platform version, that cannot be applied to the existing environment.
eb clone orders-prod --clone_name orders-green # or create the new environment from scratch
eb deploy orders-green
eb swap orders-prod --destination_name orders-greenDatabases and deployments
A database created inside an environment is deleted with it, which makes blue/green and environment replacement dangerous. Create production databases separately and pass their endpoints to the application through environment properties or Secrets Manager.
One deployment policy per requirement
Each Elastic Beanstalk deployment policy suits a different set of requirements. The following table identifies the appropriate policy for each requirement.
| Requirement | Policy |
|---|---|
| Development environment; downtime is fine; fastest | All at once |
| No extra cost; reduced capacity during deploys is acceptable | Rolling |
| Keep full capacity during deploys at a small extra cost | Rolling with additional batch |
| Full capacity and the fastest, safest rollback within the environment | Immutable |
| Send 10% of real traffic to the new version for 15 minutes first | Traffic splitting |
| Upgrade the platform version and switch with instant rollback | Blue/green: clone the environment and swap URLs |
A team that put its RDS database inside the Beanstalk environment discovers the risk when it tries blue/green: deleting the old environment would delete the database. Databases belong outside the environment, referenced through environment properties.
A deployment must keep full capacity, must not change the existing instances, and must stay in the same environment. Which policy fits?
Show answer
Immutable. It launches the new version on new instances in a temporary Auto Scaling group and moves them into the environment once they are healthy. Rolling with additional batch also keeps capacity but updates existing instances, and blue/green needs a second environment.
Exam Tips
Remember for the exam
- Zero downtime and the quickest rollback at full capacity point to an immutable deployment.
- When downtime is acceptable and speed and cost matter most, choose all at once.
- Full capacity during a rolling deployment at small extra cost points to rolling with additional batch.
- Testing a new version on a percentage of real traffic points to traffic splitting.
- Blue/green on Elastic Beanstalk uses two environments and a URL swap; keep the database outside both.