I want to list all the CNAME records in a certain hosted zone. Let's say I have over 400 records in my hosted zone. I'm using boto3
:
response_per_zone = client.list_resource_record_sets(HostedZoneId=Id, MaxItems='100')
This command list 100 records of all types. There is a lot of CNAME records missing.
How do I iterate through all the records so that I can list all the CNAME records?
You should just use the official paginator method provided by AWS: https://boto3.readthedocs.io/en/latest/reference/services/route53.html#Route53.Paginator.ListResourceRecordSets
Example code for listing CNAME records regardless of the number of records:
#!/usr/bin/env python3
paginator = client.get_paginator('list_resource_record_sets')
try:
source_zone_records = paginator.paginate(HostedZoneId='HostedZoneId')
for record_set in source_zone_records:
for record in record_set['ResourceRecordSets']:
if record['Type'] == 'CNAME':
print(record['Name'])
except Exception as error:
print('An error occurred getting source zone records:')
print(str(error))
raise