infrahouse_core.aws.route53 package

Submodules

infrahouse_core.aws.route53.exceptions module

Top level exceptions.

The exception hierarchy repeats the structure of the infrahouse_core package. Each module in the package has its own exceptions.py module. The module exceptions are inherited from the upper module exceptions.

exception infrahouse_core.aws.route53.exceptions.IHRecordNotFound[source]

Bases: IHRoute53Exception

Requested Route53 record doesn’t exist

exception infrahouse_core.aws.route53.exceptions.IHRoute53Exception[source]

Bases: IHAWSException

Route53 related InfraHouse exception

exception infrahouse_core.aws.route53.exceptions.IHZoneNotFound[source]

Bases: IHRoute53Exception

Requested Route53 zone doesn’t exist

infrahouse_core.aws.route53.zone module

Module for a Route53 zone

class infrahouse_core.aws.route53.zone.Zone(zone_id: str | None = None, zone_name: str | None = None, region: str | None = None, role_arn: str | None = None, session=None)[source]

Bases: object

Zone represents a Route53 zone. The zone can be instantiated from either a zone identifier or name. Either of them must be not None. If both are not None, zone identifier is preferred.

Parameters:
  • zone_id (str) – Zone identifier.

  • zone_name (str) – Zone name.

add_record(hostname: str, ip_address: str, ttl: int = 300)[source]

Add A record. If the hostname record already exists in the zone, the ip_address will be added. Otherwise, a new record is created.

Parameters:
  • hostname (str) – Hostname without the domain part (e.g. "www" not "www.example.com").

  • ip_address (str) – IP address to add to the record.

  • ttl (int) – Time-to-live in seconds (default 300).

Example:

zone = Zone(zone_name="example.com", region="us-east-1")
# Creates a new A record www.example.com -> 1.2.3.4
zone.add_record("www", "1.2.3.4")
# Adds a second IP to the same record
zone.add_record("www", "5.6.7.8")
delete() None[source]

Delete the hosted zone.

Deletes all non-NS/SOA record sets first, then deletes the zone itself. Idempotent – does nothing if the zone does not exist.

delete_record(hostname: str, ip_address: str)[source]

Delete an A record that matches hostname and ip_address.

property exists: bool

Check whether the hosted zone currently exists.

Returns:

True if the zone exists, False otherwise.

search_hostname(hostname) List[str][source]

Given a hostname, search an A record in the zone. The hostname should be w/o the domain part. I.e. foo, not foo.infrahouse.com.

Returns a list of IP addresses or raises IHRecordNotFound.

Parameters:

hostname (str) – Hostname

Returns:

List of IP addresses

Return type:

list(str)

Raises:

IHRecordNotFound – if the given hostname can’t be found.

property zone_id

Zone identifier. Find by name if not specified during instantiation.

property zone_name

Zone name. Find from zone identifier if not specified during instantiation.

Module contents

Route53 DNS management module.

This module provides classes for managing AWS Route53 hosted zones and DNS records.