【问题标题】:AWS Route53 CLI list-resource-record-sets by ValueAWS Route53 CLI 按值列出资源记录集
【发布时间】:2023-03-24 04:02:01
【问题描述】:

我需要在 Route53 中根据 Value 定位一条记录。我的 Route53 有 10,000 多条记录。 Web 界面当前不支持Searching by Value for a Hosted Zone with more than 2000 records。所以,我必须求助于使用AWS Route53 CLI's 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
        }
    ]
}

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

我的失败尝试

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

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

[
    "Name": "abcdxyz.mydomain.com."
]

{
    "ResourceRecords": [
        {
            "Value": "45.56.67.78"
        }
    ],
    "Type": "A",
    "Name": "abcdxyz.mydomain.com.",
    "TTL": 300
}

【问题讨论】:

    标签: amazon-web-services dns amazon-route53 jmespath


    【解决方案1】:

    应该这样做:

    aws route53 list-resource-record-sets --hosted-zone-id Z3RB47PQXVL6N2 --query "ResourceRecordSets[?ResourceRecords[?Value == '45.56.67.78'] && Type == 'A'].Name"
    

    【讨论】:

    • 太棒了!返回结果花了几分钟,但它终于做到了,这正是我想要的。由于我拥有的记录量,我想它正在解析大量数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2013-06-03
    • 2019-03-06
    • 2018-12-15
    相关资源
    最近更新 更多