Skip to content

Route53Config

Bases: BaseModel

Configuration model for AWS Route53 hosted zone and domain management.

Defines the structure and validation rules for Route53 DNS configurations, ensuring proper hosted zone identification and domain name formatting for AWS DNS record management and domain resolution.

Attributes:

Name Type Description
hosted_zone_id str

AWS Route53 hosted zone identifier for DNS record management

domain_name str

Fully qualified domain name associated with the hosted zone

Source code in mare_aws_common_lib/models/route53_config.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Route53Config(BaseModel):
    """Configuration model for AWS Route53 hosted zone and domain management.

    Defines the structure and validation rules for Route53 DNS configurations,
    ensuring proper hosted zone identification and domain name formatting for
    AWS DNS record management and domain resolution.

    Attributes:
        hosted_zone_id: AWS Route53 hosted zone identifier for DNS record management
        domain_name: Fully qualified domain name associated with the hosted zone
    """
    model_config = ConfigDict(extra="forbid")

    hosted_zone_id: str = Field(..., description="Route53 hosted zone ID")
    domain_name: str = Field(..., description="Domain name for the hosted zone")

    @field_validator('hosted_zone_id')
    @classmethod
    def validate_hosted_zone_id(cls, value: str) -> str:
        """Validate the Route53 hosted zone ID format.

        Ensures the hosted zone ID follows AWS Route53 conventions with the
        required 'Z' prefix followed by alphanumeric characters, preventing
        invalid zone references that would cause DNS resolution failures.

        Args:
            value: Raw hosted zone ID from configuration

        Returns:
            Validated hosted zone ID

        Raises:
            ValueError: If hosted zone ID doesn't match AWS format requirements
        """
        if not re.match(r'^Z[A-Z0-9]+$', value):
            raise ValueError('Hosted zone ID must be a valid AWS hosted zone ID (starts with Z)')
        return value

    @field_validator('domain_name')
    def validate_domain_name(cls, value: str) -> str:
        """Validate the domain name format and structure.

        Applies RFC-compliant domain name validation to ensure the domain
        follows standard DNS naming conventions including proper label length,
        character restrictions, and overall domain structure requirements.

        Args:
            value: Raw domain name from configuration

        Returns:
            Validated domain name

        Raises:
            ValueError: If domain name doesn't conform to DNS naming standards
        """
        domain_pattern = r'^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$'
        if not re.match(domain_pattern, value):
            raise ValueError('Invalid domain name format')
        return value

validate_domain_name(value)

Validate the domain name format and structure.

Applies RFC-compliant domain name validation to ensure the domain follows standard DNS naming conventions including proper label length, character restrictions, and overall domain structure requirements.

Parameters:

Name Type Description Default
value str

Raw domain name from configuration

required

Returns:

Type Description
str

Validated domain name

Raises:

Type Description
ValueError

If domain name doesn't conform to DNS naming standards

Source code in mare_aws_common_lib/models/route53_config.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@field_validator('domain_name')
def validate_domain_name(cls, value: str) -> str:
    """Validate the domain name format and structure.

    Applies RFC-compliant domain name validation to ensure the domain
    follows standard DNS naming conventions including proper label length,
    character restrictions, and overall domain structure requirements.

    Args:
        value: Raw domain name from configuration

    Returns:
        Validated domain name

    Raises:
        ValueError: If domain name doesn't conform to DNS naming standards
    """
    domain_pattern = r'^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$'
    if not re.match(domain_pattern, value):
        raise ValueError('Invalid domain name format')
    return value

validate_hosted_zone_id(value) classmethod

Validate the Route53 hosted zone ID format.

Ensures the hosted zone ID follows AWS Route53 conventions with the required 'Z' prefix followed by alphanumeric characters, preventing invalid zone references that would cause DNS resolution failures.

Parameters:

Name Type Description Default
value str

Raw hosted zone ID from configuration

required

Returns:

Type Description
str

Validated hosted zone ID

Raises:

Type Description
ValueError

If hosted zone ID doesn't match AWS format requirements

Source code in mare_aws_common_lib/models/route53_config.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@field_validator('hosted_zone_id')
@classmethod
def validate_hosted_zone_id(cls, value: str) -> str:
    """Validate the Route53 hosted zone ID format.

    Ensures the hosted zone ID follows AWS Route53 conventions with the
    required 'Z' prefix followed by alphanumeric characters, preventing
    invalid zone references that would cause DNS resolution failures.

    Args:
        value: Raw hosted zone ID from configuration

    Returns:
        Validated hosted zone ID

    Raises:
        ValueError: If hosted zone ID doesn't match AWS format requirements
    """
    if not re.match(r'^Z[A-Z0-9]+$', value):
        raise ValueError('Hosted zone ID must be a valid AWS hosted zone ID (starts with Z)')
    return value
Example
from mare_aws_common_lib.models import Route53Config

# Basic domain configuration
config = Route53Config(
    hosted_zone_id="Z1234567890ABC",
    domain_name="example.com"
)