Modify the Capacity Reservation settings of your instance
When you modify an instance's Capacity Reservation settings, you change how the instance uses Capacity Reservations
throughout its lifecycle. The instance can run in any reservation, a specific
reservation, or no reservation at all. What you can change depends on whether the
instance is in the stopped or running state. For more
information about each of these settings, see CapacityReservationSpecification in the Amazon EC2 API Reference.
For a stopped instance, you can change the Capacity Reservation settings to any of the
following at any time:
-
Set CapacityReservationPreference to open – the
instance runs in any open Capacity Reservation that has matching attributes (instance type,
platform, Availability Zone, and tenancy) and available capacity. If no matching
capacity is available, the instance runs as an On-Demand Instance.
-
Set CapacityReservationPreference to none –
prevents the instance from starting in a Capacity Reservation, and prevents it from being
covered by a reservation at any point during its lifecycle. The instance runs as
an On-Demand Instance.
-
Set CapacityReservationTarget to a specific Capacity Reservation with matching
attributes.
-
Set CapacityReservationTarget to a Capacity Reservation group using its
CapacityReservationResourceGroupArn.
For a running instance, you can change the Capacity Reservation settings only when the
instance's current setting is one of the following:
-
CapacityReservationPreference is set to none.
-
The instance targets a specific Capacity Reservation that is no longer in the
active state – for example, the reservation is in a
terminal state or can't be found.
When the current setting is one of the preceding, you can transition the running
instance to one of the following:
-
Set CapacityReservationPreference to open – the
running instance can then be covered by a matching Capacity Reservation. If no matching
reservation is found, the instance continues to run as an On-Demand Instance.
-
Set CapacityReservationTarget to a specific Capacity Reservation with matching
attributes that is in the active state. This Capacity Reservation can't be a
Capacity Block or Interruptible reservation.
- Console
-
To modify instance Capacity Reservation settings
Open the Amazon EC2 console at
https://console.aws.amazon.com/ec2/.
-
Choose Instances and select the instance to
modify.
-
Choose Actions, Instance
settings, Modify Capacity Reservation
Settings.
-
For Capacity Reservation, choose one of the following
options. For a running instance, only Open and
Specify Capacity Reservation are available.
-
Open – Launches the instances
into any Capacity Reservation that has matching attributes and sufficient
capacity for the number of instances you selected. If there
is no matching Capacity Reservation with sufficient capacity, the instance
uses On-Demand capacity.
-
None – Prevents the instances
from launching into a Capacity Reservation. The instances run in On-Demand
capacity.
-
Specify Capacity Reservation – Launches the
instances into the selected Capacity Reservation. If the selected Capacity Reservation does
not have sufficient capacity for the number of instances you
selected, the instance launch fails.
-
Specify Capacity Reservation group – Launches
the instances into any Capacity Reservation with matching attributes and
available capacity in the selected Capacity Reservation group. If the
selected group does not have a Capacity Reservation with matching attributes
and available capacity, the instances launch into On-Demand
capacity.
-
Specify Capacity Reservation only – Launches
the instances into a Capacity Reservation. If a Capacity Reservation ID isn't specified, the
instances launch into an open Capacity Reservation. If capacity isn't
available, the instances fail to launch.
-
Specify Capacity Reservation Resource Group only
– Launches the instances into a Capacity Reservation in a Capacity Reservation
Resource Group. If a Capacity Reservation Resource Group ARN isn't
specified, the instances launch into an open Capacity Reservation. If
capacity isn't available, the instances fail to
launch.
- AWS CLI
-
To modify instance Capacity Reservation settings
Use the modify-instance-capacity-reservation-attributes
command.
The following example changes the Capacity Reservation preference to none.
aws ec2 modify-instance-capacity-reservation-attributes \
--instance-id i-1234567890abcdef0 \
--capacity-reservation-specification CapacityReservationPreference=none
The following example the target to a specific Capacity Reservation.
aws ec2 modify-instance-capacity-reservation-attributes \
--instance-id i-1234567890abcdef0 \
--capacity-reservation-specification \
CapacityReservationTarget={CapacityReservationId=cr-1234567890abcdef0}
The following example changes the target to a specific Capacity Reservation group.
aws ec2 modify-instance-capacity-reservation-attributes \
--instance-id i-1234567890abcdef0 \
--capacity-reservation-specification \
CapacityReservationTarget={CapacityReservationResourceGroupArn=arn:aws:resource-groups:us-west-2:123456789012:group/my-cr-group}
The following example changes the Capacity Reservation preference to
capacity-reservation-only. Because it doesn't specify a Capacity Reservation,
instances launch into any open Capacity Reservation with matching attributes and
available capacity.
aws ec2 modify-instance-capacity-reservation-attributes \
--instance-id i-1234567890abcdef0 \
--capacity-reservation-specification CapacityReservationPreference=capacity-reservation-only
The following example changes the Capacity Reservation preference to
capacity-reservation-only and changes the target
to a specific Capacity Reservation. If capacity isn't available in the specified Capacity Reservation,
the instances fail to launch.
aws ec2 modify-instance-capacity-reservation-attributes \
--instance-id i-1234567890abcdef0 \
--capacity-reservation-specification \
CapacityReservationPreference=capacity-reservation-only \
CapacityReservationTarget={CapacityReservationId=cr-1234567890abcdef0}
- PowerShell
-
To modify instance Capacity Reservation settings
Use the Edit-EC2InstanceCapacityReservationAttribute cmdlet.
The following example changes the Capacity Reservation preference to none.
Edit-EC2InstanceCapacityReservationAttribute `
-InstanceId i-1234567890abcdef0 `
-CapacityReservationSpecification_CapacityReservationPreference "none"
The following example the target to a specific Capacity Reservation.
Edit-EC2InstanceCapacityReservationAttribute `
-InstanceId i-1234567890abcdef0 `
-CapacityReservationTarget_CapacityReservationId cr-1234567890abcdef0
The following example changes the target to a specific Capacity Reservation group.
Edit-EC2InstanceCapacityReservationAttribute `
-InstanceId i-1234567890abcdef0 `
-CapacityReservationTarget_CapacityReservationResourceGroupArn `
"arn:aws:resource-groups:us-west-2:123456789012:group/my-cr-group"
The following example changes the Capacity Reservation preference to
capacity-reservation-only. Because it doesn't specify a Capacity Reservation,
instances launch into any open Capacity Reservation with matching attributes and
available capacity.
Edit-EC2InstanceCapacityReservationAttribute `
-InstanceId i-1234567890abcdef0 `
-CapacityReservationSpecification_CapacityReservationPreference "capacity-reservation-only"
The following example changes the Capacity Reservation preference to
capacity-reservation-only and changes the target
to a specific Capacity Reservation. If capacity isn't available in the specified Capacity Reservation,
the instances fail to launch.
Edit-EC2InstanceCapacityReservationAttribute `
-InstanceId i-1234567890abcdef0 `
-CapacityReservationSpecification_CapacityReservationPreference "capacity-reservation-only" `
-CapacityReservationTarget_CapacityReservationId cr-1234567890abcdef0