Lesson 2 of 2 AWS Elastic Beanstalk

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.

PolicyHow it worksDowntimeCapacity during deployRollback
All at onceDeploys to every instance togetherYesNone while deployingRedeploy the old version
RollingUpdates instances in batchesNoReduced by one batchAnother rolling deployment
Rolling with additional batchLaunches an extra batch first, then rollsNoFullAnother rolling deployment
ImmutableDeploys to new instances in a temporary Auto Scaling group, then moves them into the original groupNoFull (doubles briefly)Fast: terminate the new instances
Traffic splittingSends a percentage of traffic to new instances for an evaluation period (canary)NoFull (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.

The following diagram shows each policy midway through deploying version 2 to an environment of six instances.

Elastic Beanstalk deployment policies, shown midway through deploying version 2 to six instances. All at once updates every instance together and causes downtime. Rolling updates batches, reducing capacity. Rolling with additional batch launches an extra batch first to keep full capacity. Immutable launches a full set of new instances in a temporary Auto Scaling group, so rollback means terminating them. Traffic splitting does the same but sends only a percentage of traffic to the new instances.
Policies that launch new instances keep full capacity and roll back quickly, at the cost of extra instances during the deployment.
Sort into groups

Name the deployment policy

Exam skills 3.3.6

Recognise Elastic Beanstalk deployment policies from their behaviour.

Log in to try this activity Interactive activities are free with an account.

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"          # minutes

The example above configures a traffic-splitting deployment. The following list describes further settings and behaviour of deployment policies.

  • BatchSizeType (Percentage or Fixed) and BatchSize control 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-green
Put in order

A blue/green release

Exam skills 3.3.6 · 3.3.7

Put the steps of an Elastic Beanstalk blue/green release in order.

Log in to try this activity Interactive activities are free with an account.

Databases 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.

Worked example

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.

RequirementPolicy
Development environment; downtime is fine; fastestAll at once
No extra cost; reduced capacity during deploys is acceptableRolling
Keep full capacity during deploys at a small extra costRolling with additional batch
Full capacity and the fastest, safest rollback within the environmentImmutable
Send 10% of real traffic to the new version for 15 minutes firstTraffic splitting
Upgrade the platform version and switch with instant rollbackBlue/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.

Check yourself

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.