Deploying to EC2 Auto Scaling Groups and AWS Elastic Beanstalk
Instance-based applications are often deployed by replacing instances rather than updating them. This lesson explains how launch templates and instance refresh roll out new AMIs and configurations, how CloudFormation update policies control Auto Scaling group replacement, and how AWS Elastic Beanstalk implements each deployment strategy through its deployment policies and environment swaps.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how launch template versions and instance refresh replace instances in an Auto Scaling group.
- Describe instance refresh settings, including healthy percentages, checkpoints, skip matching and rollback.
- Distinguish between the CloudFormation AutoScalingRollingUpdate and AutoScalingReplacingUpdate policies.
- Compare the Elastic Beanstalk deployment policies and blue/green deployment with a CNAME swap.
Launch Templates and Versions
An Auto Scaling group launches instances from a launch template, which specifies the AMI, instance type, instance profile, security groups, user data and other settings. Launch templates are versioned: each change creates a new numbered version, and the group can reference a specific version, the $Default version or the $Latest version. Changing the template affects only instances launched afterwards; existing instances keep running with the configuration they were launched with. Rolling out a new AMI therefore requires replacing existing instances.
Instance Refresh
Instance refresh replaces the instances in an Auto Scaling group in a controlled, rolling fashion. It terminates and launches instances in batches while keeping a minimum percentage of the group healthy, and it can specify a desired configuration, such as a new launch template version, so that the group is updated and refreshed in one operation. Its main settings are described below.
- Minimum healthy percentage (default 90%): the share of desired capacity that must stay in service and healthy. Lower values replace more instances per batch and finish faster.
- Maximum healthy percentage (100% to 200%): allows the group to launch new instances before terminating old ones. A value above 100% keeps full capacity during the refresh, at higher cost.
- Instance warmup: the time after a new instance is in service before it counts as healthy for the refresh, so that applications can finish starting.
- Checkpoints: percentages at which the refresh pauses for a set time, such as after 10% and 50%, which gives time to verify the new instances, a pattern similar to a canary.
- Skip matching: skips instances that already match the desired configuration, which makes a restarted refresh efficient.
- Auto rollback: if the refresh fails, or if specified CloudWatch alarms enter the ALARM state, Auto Scaling rolls the group back to the previous configuration by replacing new instances with ones that use the previous launch template version.
aws autoscaling start-instance-refresh --auto-scaling-group-name orders-asg \
--desired-configuration '{"LaunchTemplate":{"LaunchTemplateName":"orders","Version":"$Latest"}}' \
--preferences '{"MinHealthyPercentage":100,"MaxHealthyPercentage":110,"InstanceWarmup":300,
"CheckpointPercentages":[10,50],"CheckpointDelay":600,"SkipMatching":true,
"AutoRollback":true,
"AlarmSpecification":{"Alarms":["orders-5xx-high"]}}'With these preferences, the group launches up to 10% extra instances before terminating old ones, so capacity stays at 100%, pauses for 10 minutes after 10% and 50% of instances are replaced, and rolls back if the 5xx alarm fires.
The following diagram shows a refresh with two checkpoints.

Launch templates and refresh
CloudFormation Update Policies for Auto Scaling Groups
When an Auto Scaling group is managed by CloudFormation, the UpdatePolicy attribute decides how CloudFormation replaces instances when the launch template or other properties change. There are two main policies.
AutoScalingRollingUpdate
Replaces instances in batches within the existing group. MaxBatchSize sets the batch size, MinInstancesInService the minimum that must stay in service, and PauseTime the wait between batches. With WaitOnResourceSignals set to true, CloudFormation waits for each new instance to send a success signal, normally with cfn-signal after its configuration completes, before continuing; if signals do not arrive within the pause time, the update fails and rolls back. SuspendProcesses suspends scaling processes such as AlarmNotification and AZRebalance during the update, so that scaling does not interfere.
AutoScalingReplacingUpdate
With WillReplace set to true, CloudFormation creates a new Auto Scaling group, waits for it to become ready (usually through a CreationPolicy with resource signals), and then deletes the old group. If the update fails, CloudFormation deletes the new group and the old group is untouched. This behaves like an immutable deployment and gives a fast, clean rollback.
A third policy, AutoScalingScheduledAction, prevents CloudFormation from resetting the group's size properties to template values when scheduled actions have changed them.
Rolling or replacing update?
AWS Elastic Beanstalk Deployment Policies
Elastic Beanstalk is a platform service that provisions and manages EC2 instances, Auto Scaling, load balancing and monitoring for web applications from an uploaded application version. Its deployment policy determines how a new version reaches the environment's instances. Each policy is explained below and then compared.
All at once
Deploys to all instances simultaneously. It is fastest but causes a short outage, and a failed deployment requires redeploying the previous version.
Rolling
Deploys to batches of instances, each batch removed from the load balancer while it is updated. Capacity is reduced by the batch size.
Rolling with additional batch
Launches an extra batch of instances first, then deploys in batches, keeping full capacity, and terminates the extra batch at the end.
Immutable
Launches a full set of new instances in a temporary Auto Scaling group, deploys the version to them and, when they pass health checks, moves them into the original group and terminates the old instances. A failure terminates the temporary group, so rollback is quick and the original instances are unaffected.
Traffic splitting
A canary deployment: like immutable, it launches new instances in a temporary group, but it sends a configured percentage of client traffic to them for an evaluation period. If health remains good, all traffic moves to the new instances; otherwise traffic returns to the old ones.
| Policy | Downtime | Capacity during deployment | Rollback | Extra instances |
|---|---|---|---|---|
| All at once | Yes | None while restarting | Manual redeploy | No |
| Rolling | No | Reduced by a batch | Manual redeploy | No |
| Rolling with additional batch | No | Full | Manual redeploy | One batch |
| Immutable | No | Full | Terminate new instances | Full set |
| Traffic splitting | No | Full | Shift traffic back | Full set |
Blue/green with a CNAME swap
Elastic Beanstalk blue/green deployment is not a deployment policy. The team clones the environment, deploys the new version to the clone and then uses Swap environment URLs, which swaps the CNAME records of the two environments. Traffic moves without changing the application's DNS name, and rollback is another swap. Because DNS records are cached by clients according to their TTL, some clients reach the old environment for a short time after a swap, so the old environment should be kept until traffic drains. If the environment includes a database created by Elastic Beanstalk, the database is tied to the environment's lifecycle, which is why production databases should be created outside Elastic Beanstalk and referenced by both environments.
Environment configuration is customised with .ebextensions configuration files and, on current Amazon Linux platforms, with platform hooks in .platform/hooks that run scripts at the prebuild, predeploy and postdeploy stages.
Rolling Out a Patched AMI
An Auto Scaling group of 20 instances defined in CloudFormation must move to a newly patched AMI. The team needs full capacity, a pause after the first few instances for verification and automatic rollback if the error-rate alarm fires.
Two approaches meet the requirements. Within CloudFormation, an AutoScalingReplacingUpdate policy with a creation policy creates a complete new group, waits for signals from its instances, and removes the old group, with automatic cleanup on failure, but it has no partial pause. Alternatively, the team updates the launch template version and starts an instance refresh with maximum healthy percentage 110, a checkpoint at 10% with a 15-minute delay, and auto rollback with the alarm specification. The instance refresh approach matches the requirement for a verification pause and alarm-based rollback most closely.
An Elastic Beanstalk environment must deploy with no reduction in capacity and with existing instances never modified, so that a failure leaves them untouched. Which deployment policy fits?
Show answer
Immutable. New instances are created in a temporary Auto Scaling group; existing instances are not changed, and a failed deployment terminates only the new instances.
Exam Tips
Remember for the exam
- Launch template changes affect only new instances; use instance refresh to replace existing ones.
- Instance refresh: MinHealthyPercentage (default 90), MaxHealthyPercentage up to 200 for full capacity, checkpoints for pauses, skip matching, and auto rollback including CloudWatch alarms.
- CloudFormation AutoScalingRollingUpdate replaces in batches (WaitOnResourceSignals with cfn-signal); AutoScalingReplacingUpdate creates a new group and deletes the old one only on success.
- Elastic Beanstalk policies: all at once, rolling, rolling with additional batch, immutable and traffic splitting (canary); blue/green uses a cloned environment and Swap environment URLs.
- Create production databases outside Elastic Beanstalk so environments can be replaced or swapped.