问题
I am trying to find out list of reserved instances that are active.
aws ec2 describe-reserved-instances --filters "Name=instance-state-State,Values=active" --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'
The above command does not work, and I think the Name
field is not right.
Any help?
Thanks
回答1:
Here's another take on it. Put the search for
State == `active`
into the query statement. The output includes labels as well. By the way, changing from single-quotes around the query to double-quotes (on a mac) will require you to escape the backticks with backslashes.
aws ec2 describe-reserved-instances --query 'ReservedInstances[?State == `active`].{Count: InstanceCount, Type: InstanceType}' --output json
Output:
[
{
"Count": 50,
"Type": "t2.medium"
},
{
"Count": 3,
"Type": "m4.2xlarge"
},
{
"Count": 17,
"Type": "m3.large"
},
{
"Count": 3,
"Type": "m3.2xlarge"
},
{
"Count": 2,
"Type": "m3.2xlarge"
},
{
"Count": 3,
"Type": "m3.xlarge"
},
{
"Count": 6,
"Type": "m4.4xlarge"
}
]
回答2:
aws ec2 describe-reserved-instances --filter Name=state,Values=active
--query 'ReservedInstances[*][InstanceType,InstanceCount]'
Output:
[
[
"m3.medium",
4
],
[
"c4.large",
5
]
]
来源:https://stackoverflow.com/questions/46942024/aws-cli-to-find-out-list-of-active-reserved-instances