AWS CLI to find out list of active reserved instances

橙三吉。 提交于 2020-01-17 14:02:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!