amazon-web-servicesamazon-ec2aws-cliaws-reserved-instances

Getting already utilized AWS Reserved Instances in AWS?


I am currently running the following query

aws ec2 describe-reserved-instances    \
  --filters "Name=state,Values=active" \
  --query "ReservedInstances[].{InstanceType:InstanceType,ProductDescription:ProductDescription,InstanceCount:InstanceCount}"

In order to obtain something resembling the following:

{
    "ProductDescription": "Linux/UNIX (Amazon VPC)",
    "InstanceType": "m3.medium",
    "InstanceCount": 44
}

I am looking to get the instances already utilized though as well and am not finding a sane way to do this I would like a report showing the following information.

{
    "ProductDescription": "Linux/UNIX (Amazon VPC)",
    "InstanceType": "m3.medium",
    "InstanceCount": 44,
    "InstancesUsed": 44,
    "UtilizationPercentage": "100%"
}

How would I end up with instances used along with utilization percentage?

NOTE

In order to get percentage I can variable cast, then use the following...

Percentage() { echo "$((200*$1/$2 % 2 + 100*$1/$2))%" ; }

Percentage 44 44 //100%

Solution

  • Well, AWS doesn't work like this. Reserved instances are not "utilized" or "not utilized" on EC2 level. The magic happens in billing. When Amazon bills you, it will match instances that were running against instances that were reserved. That means that you can't get that information with aws ec2. The only thing you can do is to try to calculate which running instances are covered by reserved instances by yourself.