Boto3 route53

From wikinotes

route53 is Amazon AWS's DNS service.


Documentation

Client Description Link
Route53 Zone/DNS/healthcheck management https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/route53.html
Route53Domains https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/route53domains.html
Route53Resolver https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/route53resolver.html

Connection

route53

session = boto3.session.Session()
client = session.client(
    service_name='route53',
    aws_access_key_id='JLjk12H/j98afrz+LKJ28jlkJfjxlki12Vahlj12fZM',
    aws_secret_access_key='ALSKDJw3erukljasdf',
)
reply = client.list_hosted_zones()

route53domains

session = boto3.session.Session()
client = session.client(
    service_name='route53domains',
    region_name='us-east-1',
    aws_access_key_id='JLjk12H/j98afrz+LKJ28jlkJfjxlki12Vahlj12fZM',
    aws_secret_access_key='ALSKDJw3erukljasdf',
)
reply = client.list_domains()

DNS Records

general info

reply = client.list_hosted_zones()           # list domains
reply = client.list_resource_record_sets()   # list all DNS records

create/delete record

dns_record = {
    'Name': 'blah.blah.com',
    'Type': 'A',
    'TTL':  300,
    'ResourceRecords': [{'Value': '10.0.0.0'}],
}
client.change_resource_record_sets(
    HostedZoneId='/hostedzone/LKJASDFJKSJA',
    ChangeBatch={
        'Comment':  'Creating an A record to ...',
        'Changes':  [
            {'Action': 'UPSERT', 'ResourceRecordSet': dns_record},
            ...
        ]
    }
)

Health Checks

NOTE:

healthcheck names are not stored on the healthcheck itself. They are assigned a value by adding a tag to the healthcheck resource with the key 'Name'.

see client.change_tags_for_resource.

client.list_health_checks()
client.create_health_check(...)
client.update_health_check(...)
client.delete_health_check(...)