Guidebook to your AWS EC2 Capacity Reservations !!
Tags: aws, ec2, cost, optimization
Published: 2023-09-26 04:05:50

Welcome to another blog on AWS EC2 capacity reservations. In simple terms 

Capacity Reservation is simply put, is about reserving capacity of EC2 of the desired choice & attributes, for the usage against your workloads.

**Why you would consider creating capacity reservation ?** 

Well, reserve capacity against a AZ, for a instance type, for a duration(time period), when you have critical workload requirements, applications demand high availability, and/or plan on disaster recovery with specified instance type & attributes. 

**Key reason** to have capacity reserved, is to overcome the situation where on-demand capacity for instance type of your need/choice goes unavailable and reserving using this feature, will make the instance type available as long as the reservation stands valid

**Facts on Capacity Reservations**
1) CR can be created/cancelled anytime. Billing beings once the CR request gets into "Active" state
2) No discounts for reserving capacity and pricing stands to be on-demand
3) Savings or RI discounts will be applied on instances given that the instance attributes matches with SP, RI parameters 
4) No commitment of tenure for the instance reservation

With this background, let us jump straight into creating CR and just not that, but create EC2 matching with CR criteria

_**Step 1**_

i) CR is accessible from EC2 Console view -> Capacity Reservations menu
ii) Name, instance AZ, tenancy, OS are core parameters & hence select as needed  
iii) Instance type is m1.large

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gn4fhk9cklh7hg3wu65w.png)

_**Step 2**_

i) Instead of time range, I made a choice to go with Manual creation of CR which means on completing the parameters & if request is active, then pricing begins to apply, as the instance is reserved(since the time CR request went active)
ii) Instance eligibility - is key for the CR to function as expected. Here, "Open" will match for any instance type matching attributes with CR request 
iii) If selection is "Targeted" then the EC2 instance launched should have the CR Request ID selected, during the launch

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bkhpl8vx412farec3jk1.png)

_**Step 3**_

i) Well, that was pretty much for the definition of CR parameters, and on "Confirm" to create a CR, below popup confirms that, CR is active, then billing starts, irrespective of EC2 with matching attributes


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahef1v4os7n1xvwjsvw8.png)

_**Step 4**_

i)  Here comes, the EC2 Instance Discovery[Instance Type] in EC2 console view menu
ii) I filtered out on m1.large, to get a view of rates against OS, storage, perforce, and other attributes of m1.large and confirm the decision on instance type selection in CR


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fudvrjy3iglzd322bes.png)

_**Step 5**_

i) Now, the CR creations complete and also in active state 
ii) Let us now, see how does it match with creation of EC2 with "Launch Instance" from here

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s6yuc0cx69paga1tbm8x.png)

_**Step 6**_

i) Starting with Name, Instance type, key pair for new instance 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptb44ezvfi72ho6r7v96.png)

_**Step 7**_

i) Though, I reserved 2 instances, am launching only 1, m1.large with same prices quoted
ii) The CR id, CR Number appears under "Advanced" section of the "Launch Instance" menu
iii) Again, CR configuration will work for just matching attributes of EC2, yet, I select CR ID, CR #, just to experience the creation

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wmwdf5jd37s553lzifq.png)

_**Step 8**_

i) Finally, the instance is created with CR Id selection and Ideally would have been launched, if we just assume, that this instance type, wasn't available on-demand, by the time we launched this 
ii) Now the Instance parameters does show the CR details

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1jqk3ym3l1l73sp7etbm.png)

_**Step 9**_

i) Best part is that, as and when the instances of matching attributes or instances creation of CR Id mapping, happens, the capacity utilization of a reservation is updated under the CR Request Details view (as below) 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wftyrieyo0b4rwbki6p.png)

_**Step 10**_

i) Now that we have seen how the EC2 creation worked, let us cancel the CR
ii) Alert message is given on 2 things; firstly, that instance no longer under reserved capacity and can get terminated, if there is no availability, secondly, the actions cancelling the CR cannot be undone

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dt9vhopod32t5f1gblyg.png)

_**Step 11**_

i) Post cancelling the CR, the instance needs to be changed for its "Reservation mode"
ii) To perform this change, the EC2 instance has to be stopped first
iii) Do note, that the CR config is still the same
iv) Option to modify the "Reservation" settings is available under "Instance -> Actions -> Instance Settings -> Modify Capacity Reservation Settings" option

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kj2e3bmdqnal3nlzn6bq.png)

_**Step 12**_

i) Selecting "None" option in order to remove the instance from "Reservation Capacity" config
ii) Other options are "Open" as the name suggest allows to run instance in any group; Specific CR.- is to select a different CR here; Specify Capacity Reservation Resource  Group - If the CR was creation with a Resource Group 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/spyhy51i9yrrn9u4sc20.png)

_**Step 13**_

i) After the change, the instance has now been moved to started state, and no CR Configuration is now mapped with the EC2 
ii) Thus the CR mapping was removed successfully

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/au9x8v9680m1fyh8g1at.png)

I believe that this is useful for folks who are intense compute planners, strategists. Welcome All !!