首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何打印route53域名

如何打印route53域名
EN

Stack Overflow用户
提问于 2017-12-21 23:53:11
回答 1查看 567关注 0票数 0

我是python的新手,正在学习,我正在写一个代码来打印一个route53托管区域的域名和类型和值。当它通过CNAME循环时,我得到的是CNAME的值,而不是它的域名。

代码语言:javascript
复制
def list(zoneid, region, profile):
  rrs = []
  aws_session = boto3.session.Session(region=region, profile=profile)
  route53 = aws_session.client('route53')
  paginator = route53.get_paginator('list_resource_record_sets')

  page = paginator.paginate(
  HostedZoneId=zoneid,
  PaginationConfig={
      'MaxItems': 500,
      'PageSize': 500
  }
  )



  for i in page:
    for record in i['ResourceRecordSets']:
      if record['Type'] == 'CNAME':
        a.extend(x['Value'] for x in record['ResourceRecords'])
      elif record['Type'] == 'A':
        a.append(record['Name'])

  return a

print recordName -提供域名。但是如何将它包含在“a.extend(x‘’Value‘for x in record’‘ResourceRecords’)”行中呢?

EN

回答 1

Stack Overflow用户

发布于 2017-12-22 07:01:36

从示例响应on the docs中可以看出,对于任何资源记录都没有可用的Value密钥

代码语言:javascript
复制
{
    'ResourceRecordSets': [
        {
            'Name': 'string',
            'Type': 'SOA'|'A'|'TXT'|'NS'|'CNAME'|'MX'|'NAPTR'|'PTR'|'SRV'|'SPF'|'AAAA'|'CAA',
            'SetIdentifier': 'string',
            'Weight': 123,
            'Region': 'us-east-1'|'us-east-2'|'us-west-1'|'us-west-2'|'ca-central-1'|'eu-west-1'|'eu-west-2'|'eu-west-3'|'eu-central-1'|'ap-southeast-1'|'ap-southeast-2'|'ap-northeast-1'|'ap-northeast-2'|'sa-east-1'|'cn-north-1'|'cn-northwest-1'|'ap-south-1',
            'GeoLocation': {
                'ContinentCode': 'string',
                'CountryCode': 'string',
                'SubdivisionCode': 'string'
            },
            'Failover': 'PRIMARY'|'SECONDARY',
            'MultiValueAnswer': True|False,
            'TTL': 123,
            'ResourceRecords': [
                {
                    'Value': 'string'
                },
            ],
            'AliasTarget': {
                'HostedZoneId': 'string',
                'DNSName': 'string',
                'EvaluateTargetHealth': True|False
            },
            'HealthCheckId': 'string',
            'TrafficPolicyInstanceId': 'string'
        },
    ],
    'IsTruncated': True|False,
    'MaxItems': 'string',
    'NextToken': 'string'
}

我认为您只需要引用Name密钥:

名称(字符串) --

要对其执行操作的域的名称。

输入完全限定的域名,例如www.example.com。您可以选择包含尾随的点。如果省略尾随的圆点,Amazon Route 53仍假定您指定的域名是完全限定的。这意味着Amazon Route 53处理www.example.com (没有尾随点)和www.example.com。(带有尾随的圆点)相同。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47928448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档