The tagging of reserved instances works the same as tagging other EC2 resources through the AWS CLI's ec2 create-tags command and specifying the reserved instances ID as the resource ID. You can find the reserved instance ID using the CLI's ec2 describe-reserved-instances command. Using an actual example, lets start off finding a reservation:
$ aws ec2 describe-reserved-instances
{
"ReservedInstances": [
{
"ReservedInstancesId": "3d092b71-5243-4e5e-b409- 86df342282ab",
"OfferingType": "No Upfront",
"AvailabilityZone": "eu-west-1c",
"End": "2017-08-12T04:48:58.000Z",
"ProductDescription": "Linux/UNIX",
"UsagePrice": 0.0,
"RecurringCharges": [
{
"Amount": 0.01,
"Frequency": "Hourly"
}
],
"Start": "2016-08-12T04:48:59.763Z",
"State": "active",
"FixedPrice": 0.0,
"CurrencyCode": "USD",
"Duration": 31536000,
"InstanceTenancy": "default",
"InstanceType": "t2.micro",
"InstanceCount": 1
}
]
}
Next, lets add a tag indicating that this reservation is intended for the "production" stack.:
$ aws ec2 create-tags --resources 3d092b71-5243-4e5e-b409- 86df342282ab --tags Key=Stack,Value=production
Checking the result:
$ aws ec2 describe-reserved-instances
{
"ReservedInstances": [
{
"ReservedInstancesId": "3d092b71-5243-4e5e-b409- 86df342282ab",
"OfferingType": "No Upfront",
"AvailabilityZone": "eu-west-1c",
"End": "2017-08-12T04:48:58.000Z",
"ProductDescription": "Linux/UNIX",
"Tags": [
{
"Value": "production",
"Key": "Stack"
}
],
"UsagePrice": 0.0,
"RecurringCharges": [
{
"Amount": 0.01,
"Frequency": "Hourly"
}
],
"Start": "2016-08-12T04:48:59.763Z",
"State": "active",
"FixedPrice": 0.0,
"CurrencyCode": "USD",
"Duration": 31536000,
"InstanceTenancy": "default",
"InstanceType": "t2.micro",
"InstanceCount": 1
}
]
}
Great we have a tag but what if we have hundreds of reservations, a long list of reservations is not particularly useful for quickly identifying the reservations related to a component or stack. The CLI's query and output functionality can help here:
$ aws ec2 describe-reserved-instances --query 'ReservedInstances[*].{AZ: AvailabilityZone,Type: InstanceType,Expiry:End,stack: Tags[?Key==`Stack`][?Value==` production`]}' --output=table
------------------------------ --------------------------
| DescribeReservedInstances |
+-------------+--------------- -------------+-----------+
| AZ | Expiry | Type |
+-------------+--------------- -------------+-----------+
| eu-west-1c | 2017-08-12T04:48:58.000Z | t2.micro |
+-------------+--------------- -------------+-----------+
Not quite the console view but easy enough to see that we have one reservation for the "production" Stack.
------------------------------
| DescribeReservedInstances
+-------------+---------------
| AZ | Expiry | Type |
+-------------+---------------
| eu-west-1c | 2017-08-12T04:48:58.000Z | t2.micro |
+-------------+---------------
Not quite the console view but easy enough to see that we have one reservation for the "production" Stack.