AWS CLI,用于查找活动保留实例的列表

时间:2017-10-25 21:03:00

标签: amazon-web-services amazon-ec2 aws-cli

我正在尝试找出活动的保留实例列表。

aws ec2 describe-reserved-instances --filters  "Name=instance-state-State,Values=active" --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'

以上命令不起作用,我认为Name字段不正确。 有帮助吗? 感谢

2 个答案:

答案 0 :(得分:1)

aws ec2 describe-reserved-instances --filter Name=state,Values=active
        --query 'ReservedInstances[*][InstanceType,InstanceCount]'

输出:

[
    [
        "m3.medium",
        4
    ],
    [
        "c4.large",
        5
    ]
]

答案 1 :(得分:1)

这是另一种看法。搜索

State == `active`

进入查询语句。输出还包括标签。顺便说一句,从查询周围的单引号更改为双引号(在mac上)将要求您使用反斜杠转义反引号。

aws ec2 describe-reserved-instances --query 'ReservedInstances[?State == `active`].{Count: InstanceCount, Type: InstanceType}' --output json

输出:

[
    {
        "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"
    }
]