

# PurchaseHostReservation
<a name="API_PurchaseHostReservation"></a>

Purchase a reservation with configurations that match those of your Dedicated Host. You must have active Dedicated Hosts in your account before you purchase a reservation. This action results in the specified reservation being purchased and charged to your account.

## Request Parameters
<a name="API_PurchaseHostReservation_RequestParameters"></a>

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see [Common Query Parameters](CommonParameters.md).

 **ClientToken**   
Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see [Ensuring Idempotency](https://docs.amazonaws.cn/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html).  
Type: String  
Required: No

 **CurrencyCode**   
The currency in which the `totalUpfrontPrice`, `LimitPrice`, and `totalHourlyPrice` amounts are specified. At this time, the only supported currency is `USD`.  
Type: String  
Valid Values: `USD`   
Required: No

 **HostIdSet.N**   
The IDs of the Dedicated Hosts with which the reservation will be associated.  
Type: Array of strings  
Required: Yes

 **LimitPrice**   
The specified limit is checked against the total upfront cost of the reservation (calculated as the offering's upfront cost multiplied by the host count). If the total upfront cost is greater than the specified price limit, the request fails. This is used to ensure that the purchase does not exceed the expected upfront cost of the purchase. At this time, the only supported currency is `USD`. For example, to indicate a limit price of USD 100, specify 100.00.  
Type: String  
Required: No

 **OfferingId**   
The ID of the offering.  
Type: String  
Required: Yes

 **TagSpecification.N**   
The tags to apply to the Dedicated Host Reservation during purchase.  
Type: Array of [TagSpecification](API_TagSpecification.md) objects  
Required: No

## Response Elements
<a name="API_PurchaseHostReservation_ResponseElements"></a>

The following elements are returned by the service.

 **clientToken**   
Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see [Ensuring Idempotency](https://docs.amazonaws.cn/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html).  
Type: String

 **currencyCode**   
The currency in which the `totalUpfrontPrice` and `totalHourlyPrice` amounts are specified. At this time, the only supported currency is `USD`.  
Type: String  
Valid Values: `USD` 

 **purchase**   
Describes the details of the purchase.  
Type: Array of [Purchase](API_Purchase.md) objects

 **requestId**   
The ID of the request.  
Type: String

 **totalHourlyPrice**   
The total hourly price of the reservation calculated per hour.  
Type: String

 **totalUpfrontPrice**   
The total amount charged to your account when you purchase the reservation.  
Type: String

## Errors
<a name="API_PurchaseHostReservation_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

## Examples
<a name="API_PurchaseHostReservation_Examples"></a>

### Example
<a name="API_PurchaseHostReservation_Example_1"></a>

This example uses the same configuration information from [GetHostReservationPurchasePreview](API_GetHostReservationPurchasePreview.md) to make the purchase and associate the offering with the specified Dedicated Host.

#### Sample Request
<a name="API_PurchaseHostReservation_Example_1_Request"></a>

```
https://ec2.amazonaws.com/?Action=PurchaseHostReservation
&OfferingId=hro-0eb3541dght849c2d
&HostIdSet=h-0fgr9ddb0ecd0a1cd
&AUTHPARAMS
```

#### Sample Response
<a name="API_PurchaseHostReservation_Example_1_Response"></a>

```
<PurchaseHostReservationResult xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
    <requestId>d4904fd9-84c3-b40d-gtyk-a9983EXAMPLE</requestId>
        <purchase>
            <item>
                <duration>31536000</duration>
                <upfrontPrice>7453.000</upfrontPrice>
                <paymentOption>PartialUpfront</paymentOption>
                <instanceFamily>m4</instanceFamily>
                <hourlyPrice>0.850</hourlyPrice>
                <hostIdSet>
                    <item>h-0fgr9ddb0ecd0a1cd</item>
                </hostIdSet>
            </item>
       </purchase>
       <totalHourlyPrice>0.850<totalHourlyPrice>
       <totalUpfrontPrice>7453.000<totalUpfrontPrice>
</PurchaseHostReservationResult>
```

## See Also
<a name="API_PurchaseHostReservation_SeeAlso"></a>

For more information about using this API in one of the language-specific Amazon SDKs, see the following:
+  [Amazon Command Line Interface V2](https://docs.amazonaws.cn/goto/cli2/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for .NET V4](https://docs.amazonaws.cn/goto/DotNetSDKV4/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for C\+\+](https://docs.amazonaws.cn/goto/SdkForCpp/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for Go v2](https://docs.amazonaws.cn/goto/SdkForGoV2/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for Java V2](https://docs.amazonaws.cn/goto/SdkForJavaV2/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for JavaScript V3](https://docs.amazonaws.cn/goto/SdkForJavaScriptV3/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for Kotlin](https://docs.amazonaws.cn/goto/SdkForKotlin/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for PHP V3](https://docs.amazonaws.cn/goto/SdkForPHPV3/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for Python (Boto3)](https://docs.amazonaws.cn/goto/boto3/ec2-2016-11-15/PurchaseHostReservation) 
+  [Amazon SDK for Ruby V3](https://docs.amazonaws.cn/goto/SdkForRubyV3/ec2-2016-11-15/PurchaseHostReservation) 