

# Configure your Auto Scaling group to launch instances with Capacity Reservations
<a name="capacity-reservation-create-asg-procedure"></a>

To configure your Auto Scaling group to launch instances with Amazon EC2 Capacity Reservations, choose the procedure that matches your approach:
+ For On-Demand Capacity Reservations, see [Use a Capacity Reservation specification](#use-a-capacity-reservation-specification).
+ For background on Capacity Reservation targeting options and behavior, see [Target Capacity Reservations from your Auto Scaling group](target-capacity-reservations.md).

## Use a Capacity Reservation specification
<a name="use-a-capacity-reservation-specification"></a>

Use one of the following methods to configure a Capacity Reservation specification when you create a new Auto Scaling group.

------
#### [ Console ]

**To configure a Capacity Reservation specification on a new group (console)**

1. Follow the steps in [Create an Auto Scaling group using the Amazon EC2 launch wizard](create-asg-ec2-wizard.md), up to step 2.

1. On the **Choose instance launch options** page, under **Additional capacity settings**, choose a Capacity Reservation preference. Optionally, choose a Capacity Reservation target. For more information, see [Capacity Reservation preference](target-capacity-reservations.md#asg-capacity-reservation-preference) and [Capacity Reservation target](target-capacity-reservations.md#capacity-reservation-target).

1. Continue with the remaining steps of the wizard.

------
#### [ Amazon CLI ]

Add the `--capacity-reservation-specification` parameter to the [create-auto-scaling-group](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/create-auto-scaling-group.html) command. The parameter accepts a preference and an optional target. For details, see [Capacity Reservation preference](target-capacity-reservations.md#asg-capacity-reservation-preference) and [Capacity Reservation target](target-capacity-reservations.md#capacity-reservation-target).

The following example creates an Auto Scaling group with a preference of `capacity-reservations-only` and a specific Capacity Reservation as the target.

```
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name {{my-asg}} \
    --launch-template LaunchTemplateName={{my-launch-template}} \
    --min-size {{1}} --max-size {{10}} --desired-capacity {{5}} \
    --vpc-zone-identifier "{{subnet-abc1234a}},{{subnet-abc1234b}}" \
    --capacity-reservation-specification '{
        "CapacityReservationPreference": "capacity-reservations-only",
        "CapacityReservationTarget": {
            "CapacityReservationIds": ["{{cr-1234567890abcdef1}}"]
        }
    }'
```

------

### Update an existing Auto Scaling group
<a name="update-an-existing-auto-scaling-group"></a>

To change the Capacity Reservation specification on an existing Auto Scaling group, use one of the following methods.

------
#### [ Console ]

**To change the Capacity Reservation specification on an existing group (console)**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/), and choose **Auto Scaling Groups** from the navigation pane.

1. From the navigation bar at the top, choose the Amazon Web Services Region where your Auto Scaling group is located.

1. Select the check box next to your Auto Scaling group. A split pane opens at the bottom of the page.

1. On the **Details** tab, under **Capacity Reservation preference**, choose **Edit**.

1. Choose a Capacity Reservation preference and, optionally, a Capacity Reservation target.

1. Choose **Update**.

------
#### [ Amazon CLI ]

Add the `--capacity-reservation-specification` parameter to the [update-auto-scaling-group](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/update-auto-scaling-group.html) command.

The following example updates an Auto Scaling group to use a Capacity Reservation Resource Group as the target with a preference of `capacity-reservations-first`.

```
aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name {{my-asg}} \
    --capacity-reservation-specification '{
        "CapacityReservationPreference": "capacity-reservations-first",
        "CapacityReservationTarget": {
            "CapacityReservationResourceGroupArns": ["{{arn:aws:resource-groups:us-east-1:123456789012:group/my-cr-group}}"]
        }
    }'
```

------