You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于Value定位Route53超万条记录?CLI查询方案

How to Filter Route53 Resource Records by Value Using CLI (For 10k+ Record Zones)

Dealing with large Route53 hosted zones (10,000+ records) is frustrating when the web UI can't filter by value for zones over 2000 records. The AWS CLI's list-resource-record-sets command combined with JMESPath queries is the perfect workaround here. Let's break down how to do this effectively:

Basic Command Structure

The core command uses --hosted-zone-id to target your zone, and --query with JMESPath syntax to filter records by their value. Here's the base template:

aws route53 list-resource-record-sets --hosted-zone-id YOUR_HOSTED_ZONE_ID --query 'YOUR_JMESPATH_QUERY' --output table

Key JMESPath Filtering Examples

1. Exact Value Match (Any Record Type)

To find all records where the value exactly matches your target (e.g., "192.168.1.1"), use this query. It checks the ResourceRecords array (where values are stored) for a matching entry:

aws route53 list-resource-record-sets --hosted-zone-id Z3RB47PQXVL6N2 --query 'ResourceRecordSets[?ResourceRecords[?Value==`"192.168.1.1"`]]' --output table

2. Exact Match for a Specific Record Type

If you want to narrow it down to a specific type (like A or CNAME), add a type filter:

# Filter A records with exact value
aws route53 list-resource-record-sets --hosted-zone-id Z3RB47PQXVL6N2 --query 'ResourceRecordSets[?Type==`A` && ResourceRecords[?Value==`"192.168.1.1"`]]' --output table

# Filter CNAME records pointing to example.com
aws route53 list-resource-record-sets --hosted-zone-id Z3RB47PQXVL6N2 --query 'ResourceRecordSets[?Type==`CNAME` && ResourceRecords[?Value==`"example.com."`]]' --output table

Note: Route53 stores CNAME values with a trailing dot, so make sure to include that in your query.

3. Partial/Contains Match

If you need to find values that contain a specific string (e.g., all records pointing to a subdomain of example.com), use the contains() function:

aws route53 list-resource-record-sets --hosted-zone-id Z3RB47PQXVL6N2 --query 'ResourceRecordSets[?ResourceRecords[?contains(Value, `"example.com"`)]].{Name: Name, Type: Type, Value: ResourceRecords[0].Value}' --output table

This also formats the output to only show relevant fields (Name, Type, Value) for readability.

4. Handle Pagination Automatically

For zones with 10k+ records, the CLI will automatically paginate results. If you want to export all matching records to a JSON file (instead of viewing them in the terminal), use this command:

aws route53 list-resource-record-sets --hosted-zone-id Z3RB47PQXVL6N2 --query 'ResourceRecordSets[?ResourceRecords[?Value==`"192.168.1.1"`]]' > matching_records.json

Quick Tips

  • Always wrap your target value in both backticks and double quotes (`"VALUE"`) within the JMESPath query to avoid syntax errors.
  • Use --output table for human-readable results, or --output json for programmatic use.
  • If you need to filter weighted or latency records, adjust the query to include fields like SetIdentifier if needed.

内容的提问来源于stack exchange,提问作者Aaron St Clair

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:09:07