AWS Route53 CLI按值列出列表-资源-记录集

Aar*_*air 2 dns amazon-web-services amazon-route53 jmespath

我需要基于Value在Route53中找到一条记录。我的Route53有10,000多个记录。Web界面当前不支持按值搜索具有2000条以上记录的托管区域。因此,我必须诉诸使用AWS Route53 CLI的list-resource-record-sets命令和--query参数。此参数使用JMESPath选择或过滤结果集。

因此,让我们看一下我们正在使用的结果集。

$ aws route53 list-resource-record-sets --hosted-zone-id  Z3RB47PQXVL6N2 --max-items 5 --profile myprofile
{
    "NextToken": "eyJTdGFydFJlY29yZE5hbWUiOiBudWxsLCAiU3RhcnRSZWNvcmRJZGVudGlmaWVyIjogbnVsbCwgIlN0YXJ0UmVjb3JkVHlwZSI6IG51bGwsICJib3RvX3RydW5jYXRlX2Ftb3VudCI6IDV9",
    "ResourceRecordSets": [
        {
            "ResourceRecords": [
                {
                    "Value": "ns-1264.awsdns-30.org."
                },
                {
                    "Value": "ns-698.awsdns-23.net."
                },
                {
                    "Value": "ns-1798.awsdns-32.co.uk."
                },
                {
                    "Value": "ns-421.awsdns-52.com."
                }
            ],
            "Type": "NS",
            "Name": "mydomain.com.",
            "TTL": 300
        },
        {
            "ResourceRecords": [
                {
                    "Value": "ns-1264.awsdns-30.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"
                }
            ],
            "Type": "SOA",
            "Name": "mydomain.com.",
            "TTL": 300
        },
        {
            "ResourceRecords": [
                {
                    "Value": "12.23.34.45"
                }
            ],
            "Type": "A",
            "Name": "abcdefg.mydomain.com.",
            "TTL": 300
        },
        {
            "ResourceRecords": [
                {
                    "Value": "34.45.56.67"
                }
            ],
            "Type": "A",
            "Name": "zyxwvut.mydomain.com.",
            "TTL": 300
        },
        {
            "ResourceRecords": [
                {
                    "Value": "45.56.67.78"
                }
            ],
            "Type": "A",
            "Name": "abcdxyz.mydomain.com.",
            "TTL": 300
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

理想情况下,我需要找到ResourceRecordSets.Name,但我绝对可以返回具有ResourceRecordSet的任何记录的整个对象ResourceRecords.Value == 45.56.67.78

我的失败尝试

// My first attempt was to use filters on two levels, but this always returns an empty array
ResourceRecordSets[?Type == 'A'].ResourceRecords[?Value == '45.56.67.78'][]
[]

// Second attempt came after doing more research on JMESPath. I could not find any good examples using filters on two levels, so I do not filter on ResourceRecordSets
ResourceRecordSets[*].ResourceRecords[?Value == '45.56.67.78']
[
    [],
    [],
    [
        {
            "Value": "45.56.67.78"
        }
    ],
    [],
    []
]
Run Code Online (Sandbox Code Playgroud)

在桌子上on了一下头之后,我决定咨询专家。使用上面的示例,我如何利用JMESPath和AWS Route53 CLI返回以下两个带有记录的记录之一Value == 45.56.67.78

[
    "Name": "abcdxyz.mydomain.com."
]
Run Code Online (Sandbox Code Playgroud)

要么

{
    "ResourceRecords": [
        {
            "Value": "45.56.67.78"
        }
    ],
    "Type": "A",
    "Name": "abcdxyz.mydomain.com.",
    "TTL": 300
}
Run Code Online (Sandbox Code Playgroud)

Dus*_*jic 5

应该这样做:

aws route53 list-resource-record-sets --hosted-zone-id Z3RB47PQXVL6N2 --query "ResourceRecordSets[?ResourceRecords[?Value == '45.56.67.78'] && Type == 'A'].Name"
Run Code Online (Sandbox Code Playgroud)