Skip to content

Commit

Permalink
Fix a bug on scan operation due to Route53 results limit
Browse files Browse the repository at this point in the history
Set explicitly a limit of results from a Route53 query to the maximum
number of items there could be on a table, to avoid pagination.
Otherwise, there's a default of 100 which might produce invalid results
(e.g. scanning resources of another table and reaching the limit,
therefore not returning all results of the scanned table).
  • Loading branch information
ahachete committed Nov 26, 2022
1 parent e4d21a5 commit d78516d
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class Route53Manager {

private static final int MAX_VALUES_PER_RESOURCE_RECORD = 400;

private static final int MAX_RECORDS_HOSTED_ZONE = 10_000;

// Max number of items on a table: max records minus SOA and NS for the zone minus a single table definition SRV
private static final int MAX_ITEMS_HOSTED_ZONE = MAX_RECORDS_HOSTED_ZONE - 2 - 1;

private static final Logger LOGGER = LoggerFactory.getLogger(Route53Manager.class);

@ConfigProperty(name = "hosted_zone")
Expand All @@ -51,7 +56,7 @@ void getZoneDomainNameFromHostedZone() {
var getHostedZoneRequest = GetHostedZoneRequest.builder()
.id(hostedZone)
.build();

route53AsyncClient.getHostedZone(getHostedZoneRequest)
.orTimeout(ROUTE53_API_CALLS_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.whenComplete(
Expand Down Expand Up @@ -245,6 +250,7 @@ private Stream<ResourceRecordSet> listAllRecords(RRType rrType) {
return route53AsyncClient.listResourceRecordSets(
ListResourceRecordSetsRequest.builder()
.hostedZoneId(hostedZone)
.maxItems("" + MAX_ITEMS_HOSTED_ZONE)
.startRecordType(rrType)
// Surprisingly, if we don't include .startRecordName() we get a 400 - InvalidInputException
.startRecordName(FIRST_LETTER_FIRST_POSSIBLE_LEXICOGRAPHICAL_DOMAIN_NAME_ROUTE53_ESCAPED)
Expand Down

0 comments on commit d78516d

Please sign in to comment.