从 route53 托管区域请求记录以检索所有记录时如何执行批处理

How to perform batching when requesting records from route53 hosted zone to retrieve all the records

我的托管区域有超过 2500 条记录。我编写了 java 代码,使用 ListResourceRecordSetsRequest 从指定的托管区域检索资源记录。但是,它最多只列出 300 条记录。如何执行批处理以便检索所有 2500 条记录?

ListResourceRecordSetsRequest request = ListResourceRecordSetsRequest.builder()
                .hostedZoneId(hostedZone.id())
                .maxItems("1000")
                .build() as ListResourceRecordSetsRequest
        ListResourceRecordSetsResponse listResourceRecordSets = route53Client.listResourceRecordSets(request);
        List<ResourceRecordSet> records = listResourceRecordSets.resourceRecordSets();
        return records

上面的代码是我使用的,它returns最多300条记录

您可以使用以下代码段遍历所有记录。

final ListResourceRecordSetsRequest listRecordSetRequest = new ListResourceRecordSetsRequest().
                withHostedZoneId(hostedZone.getId());
ListResourceRecordSetsResult listRecordSetResult;
final List<ResourceRecordSet> resourceRecordSets = new ArrayList<>();
do {
      listRecordSetResult = route53.listResourceRecordSets(listRecordSetRequest);
      resourceRecordSets.addAll(listRecordSetResult.getResourceRecordSets());
            listRecordSetRequest.setStartRecordIdentifier(listRecordSetResult.getNextRecordIdentifier());
} while (listRecordSetResult.isTruncated());