#! /bin/bash
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query "Reservations[].Instances[?InstanceLifecycle!=\`spot\`].[InstanceId,InstanceType]" --output text|awk -F "\t" '{a[$3$2]+=1}END{ for (i in a) print i,"\t", a[i],"\t"}'|sort > running_noaz.txt
aws ec2 describe-reserved-instances --filters "Name=state,Values=active" "Name=instance-type,Values=*" --query "ReservedInstances[].[InstanceType,InstanceCount]" --output text|awk -F "\t" '{a[$1]+=$2}END{ for (i in a) print i,"\t\t",a[i]}'|sort > reserved_noaz.txt
echo "[InstanceType] [Running] [Reserved]"
awk -F "\t" '{a[$1]+=$2;b[$1]+=$3}END{ for (i in a) print i,"\t",a[i],"\t",b[i]}' running_noaz.txt reserved_noaz.txt|sort
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme