【问题标题】:merge aws cli results合并 aws cli 结果
【发布时间】:2020-09-26 19:21:17
【问题描述】:

我试图弄清楚如何加入 aws cli 分页输出的结果。 假设查询如下所示: aws ec2 describe-snapshots --output json --max-items 100 --starting-token ABC-123 使用下一个令牌,我正在生成 N 个文件:out.0.json、out.1.json、...

每个这样的文件看起来像这样:

{
"Snapshots": [
    {
        "Description": "hvm/ubuntu-vivid-amd64-server-20160119",
        "Encrypted": false,
        "OwnerId": "0123456789",
        "Progress": "100%",
        "SnapshotId": "snap-0001",
        "StartTime": "2016-01-19T19:24:47+00:00",
        "State": "completed",
        "VolumeId": "vol-0001",
        "VolumeSize": 8
    },
    {
        "Description": "ebs/ubuntu-trusty-i386-server-20151007",
        "Encrypted": false,
        "OwnerId": "0123456789",
        "Progress": "100%",
        "SnapshotId": "snap-1234",
        "StartTime": "2015-10-07T23:09:20+00:00",
        "State": "completed",
        "VolumeId": "vol-1235",
        "VolumeSize": 8
    },
    {
        "Description": "hvm-io1/ubuntu-precise-amd64-server-20150512",
        "Encrypted": false,
        "OwnerId": "0123456789",
        "Progress": "100%",
        "SnapshotId": "snap-1235",
        "StartTime": "2015-05-13T02:17:25+00:00",
        "State": "completed",
        "VolumeId": "vol-1235",
        "VolumeSize": 8
    },
    .......

如何将所有文件的快照列表合并为一个?我尝试使用合并的 jq,但似乎没有任何效果

【问题讨论】:

    标签: json jq aws-cli depagination


    【解决方案1】:

    这是一个既简单又高效的解决方案。它假定out.*.json 按要求的顺序标识相关文件(如果有)。

    jq -n '{Snapshots: [inputs.Snapshots] | add}' out.*.json
    

    注意这里需要 -n 选项。

    【讨论】:

    • 完美——只是第一个“快照”拼错了
    猜你喜欢
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 2020-11-13
    相关资源
    最近更新 更多