gpt4 book ai didi

amazon-web-services - AWS Route 53 使用 boto3 列出 CNAME 记录

转载 作者:行者123 更新时间:2023-12-03 15:25:15 26 4
gpt4 key购买 nike

我想列出某个托管区域中的所有 CNAME 记录。假设我的托管区域中有 400 多条记录。我正在使用 boto3 :

response_per_zone = client.list_resource_record_sets(HostedZoneId=Id, MaxItems='100')

此命令列出 100 条所有类型的记录。有很多 CNAME 记录丢失。
如何遍历所有记录以便我可以列出所有 CNAME 记录?

最佳答案

您应该只使用 AWS 提供的官方分页器方法:
https://boto3.readthedocs.io/en/latest/reference/services/route53.html#Route53.Paginator.ListResourceRecordSets

列出 CNAME 记录而不考虑记录数的示例代码:

#!/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

关于amazon-web-services - AWS Route 53 使用 boto3 列出 CNAME 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41716586/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com