Configure your Auto Scaling group to launch instances with Capacity Reservations
To configure your Auto Scaling group to launch instances with Amazon EC2 Capacity Reservations and Capacity Blocks for ML, choose the procedure that matches your approach:
-
For On-Demand Capacity Reservations, see Use a Capacity Reservation specification.
-
For Capacity Blocks or interruptible Capacity Reservations, see Target Capacity Blocks or interruptible Capacity Reservations from a launch template.
-
For mixing multiple reservation types (for example, On-Demand Capacity Reservations and Capacity Blocks) in the same Auto Scaling group, see Use Distribution Segments to target multiple Capacity Reservation types.
-
For background on Capacity Reservation targeting options and behavior, see Target Capacity Reservations from your Auto Scaling group.
Use a Capacity Reservation specification
Use one of the following methods to configure a Capacity Reservation specification when you create a new Auto Scaling group.
Update an existing Auto Scaling group
To change the Capacity Reservation specification on an existing Auto Scaling group, use one of the following methods.
Target Capacity Blocks or interruptible Capacity Reservations from a launch template
You can consume Capacity Blocks or interruptible Capacity Reservations from your Auto Scaling group using launch-template-based targeting. This approach requires setting the market type on your launch template and specifying the Capacity Reservation ID as the target on your Auto Scaling group.
If your Auto Scaling group uses a mixed instances policy, we recommend using distribution segments instead, which lets you configure Capacity Reservations in one place on the Auto Scaling group. Launch-template-based targeting is required if your Auto Scaling group uses a single instance type.
Configure a launch template
In your launch template, set the following:
-
Set the instance market type (
InstanceMarketOptions.MarketType) tocapacity-blockfor a Capacity Block, orinterruptible-capacity-reservationfor an interruptible Capacity Reservation. -
Set the Capacity Reservation target (
CapacityReservationSpecification.CapacityReservationTarget.CapacityReservationId) to the Capacity Reservation ID.
The following example uses the create-launch-templateMarketType value with
interruptible-capacity-reservation.
aws ec2 create-launch-template \ --launch-template-namemy-cr-launch-template\ --launch-template-data '{ "ImageId": "ami-0abcdef1234567890", "InstanceType": "p5.48xlarge", "InstanceMarketOptions": { "MarketType": "capacity-block" }, "CapacityReservationSpecification": { "CapacityReservationTarget": { "CapacityReservationId": "cr-1234567890abcdef1" } } }'
For information about creating a launch template, see Launch templates in the Amazon EC2 User Guide.
Create an Auto Scaling group
Create an Auto Scaling group that uses the launch template. The Auto Scaling group must be configured with a subnet in the same Availability Zone as your Capacity Reservation.
The following example creates an Auto Scaling group that uses the launch template created in the previous step.
aws autoscaling create-auto-scaling-group \ --auto-scaling-group-namemy-cr-asg\ --launch-template LaunchTemplateName=my-cr-launch-template\ --min-size0--max-size4--desired-capacity4\ --vpc-zone-identifier "subnet-abc1234a"
For more information, see Create Auto Scaling groups using launch templates.
Operational guidelines
Consider the following operational guidelines when using launch template–based targeting.
-
Launch template version – Point your Auto Scaling group to a specific launch template version instead of the
$Defaultor$Latestversion. This ensures consistency for the duration of the reservation. -
Instance replacement – When a Capacity Block expires or an interruptible Capacity Reservation is reclaimed, Amazon EC2 terminates the instances running in it. The Auto Scaling health checker detects the termination and attempts to launch a replacement instance in the same manner as for any instance that fails a health check. Scaling activities for these terminations show taken out of service in response to an Amazon EC2 health check that indicated it had been terminated or stopped.
-
For Capacity Blocks – Scale in your Auto Scaling group to zero more than 30 minutes before the Capacity Block reservation end time. Amazon EC2 begins terminating any remaining instances 30 minutes before the end time. Use scheduled scaling to scale out at the reservation start and scale in before the end. Add lifecycle hooks as needed to gracefully shut down your application before the forced termination window.
-
For interruptible Capacity Reservations – Instances can be terminated with a 2-minute notice when the capacity owner reclaims capacity. Design your applications to handle graceful shutdowns. Amazon EC2 sends notifications 2 minutes before termination, and you can set up custom automation to respond to these notifications.
Override Capacity Reservation settings at the Auto Scaling group level
You can set a Capacity Reservation preference and target on your Auto Scaling group to override the settings in your launch template. For more information about the Capacity Reservation specification, see Target Capacity Reservations from your Auto Scaling group.
Considerations
-
Mixed instances policies – Launch-template-based targeting of Capacity Blocks or interruptible Capacity Reservations is not supported with mixed instances policies. To use these reservation types with a mixed instances policy, see Use Distribution Segments to target multiple Capacity Reservation types.
-
Warm pools – Warm pools are not supported when your launch template targets a Capacity Block or an interruptible Capacity Reservation.
-
One Capacity Reservation type per launch template – A launch template can target only one Capacity Reservation type. To target multiple Capacity Reservation types in one Auto Scaling group, use distribution segments.