如何使用java从路由53获取特定托管区域的所有资源记录集

时间:2018-05-14 07:51:46

标签: amazon-web-services amazon-route53

我使用下面的代码来获取所有记录,但它总是返回特定托管区域的100条记录。我想显示托管区域的所有资源记录。

public List<ResourceRecordSet> getResourceRecordSet(String hostedZoneId) {
    AmazonRoute53Client route53Client = new AmazonRoute53Client(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY));
    ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest();
    request.setHostedZoneId(hostedZoneId);
    return route53Client.listResourceRecordSets(request);
}

2 个答案:

答案 0 :(得分:0)

您必须使用pagination

答案 1 :(得分:0)

您需要对所有值进行分页并将其存储在其他集合中。

public List<ResourceRecordSet> getResourceRecordSet(String hostedZoneId) {
  AmazonRoute53Client route53Client = new AmazonRoute53Client(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY));
  String nextRecordName = null;
  List<ResourceRecordSet> allRecords = new ArrayList<>();
  do  {
    ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest();
    request.setHostedZoneId(hostedZoneId);
    if (nextRecordName != null) {
      request = request.withStartRecordName(nextRecordName);
    }
    ListResourceRecordSetsResult currentRecords = route53Client.listResourceRecordSets(request);
    nextRecordName = currentRecords.getNextRecordName();

    allRecords.addAll(currentRecords.getResourceRecordSets());
  } while (nextRecordName != null);
  return allRecords;
}