Skip to content

CloudfrontConfig

Bases: BaseModel, NameValidationMixin, AwsTypesValidationMixin

Configuration model for AWS CloudFront distribution with multi-origin support.

Defines the complete structure and validation rules for CloudFront distributions supporting multiple origin types including S3 buckets, Application Load Balancers, and VPC origins. Enforces AWS requirements for SSL certificates, WAF integration, and Route53 DNS management with comprehensive origin validation.

The configuration requires a 'default' S3 origin and supports additional origins with unique path patterns for content routing and delivery optimization.

Attributes:

Name Type Description
origins Dict[str, CloudfrontOrigin]

Dictionary of origin configurations with required 'default' S3 origin

ssl_certificate_id str

SSL certificate ID located in us-east-1 for CloudFront

web_acl_id Optional[str]

Optional AWS WAF Web ACL ID for security protection

logs_bucket Optional[Any]

Optional S3 bucket for CloudFront access logging

route53 Route53Config

Route53 configuration for domain and DNS record management

activate_additional_metrics bool

Wheter to enable additional metrics for the distribution

Source code in mare_aws_common_lib/models/cloudfront_config.py
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
class CloudfrontConfig(BaseModel, NameValidationMixin, AwsTypesValidationMixin):
    """Configuration model for AWS CloudFront distribution with multi-origin support.

    Defines the complete structure and validation rules for CloudFront distributions
    supporting multiple origin types including S3 buckets, Application Load Balancers,
    and VPC origins. Enforces AWS requirements for SSL certificates, WAF integration,
    and Route53 DNS management with comprehensive origin validation.

    The configuration requires a 'default' S3 origin and supports additional origins
    with unique path patterns for content routing and delivery optimization.

    Attributes:
        origins: Dictionary of origin configurations with required 'default' S3 origin
        ssl_certificate_id: SSL certificate ID located in us-east-1 for CloudFront
        web_acl_id: Optional AWS WAF Web ACL ID for security protection
        logs_bucket: Optional S3 bucket for CloudFront access logging
        route53: Route53 configuration for domain and DNS record management
        activate_additional_metrics: Wheter to enable additional metrics for the distribution 
    """

    model_config = ConfigDict(extra="forbid")

    origins: Dict[str, CloudfrontOrigin] = Field(..., description="Origin configurations - must include 'default' key for S3 origin")
    ssl_certificate_id: str = Field(..., description="SSL certificate ID (must be in us-east-1 for CloudFront)")
    web_acl_id: Optional[str] = Field(None, description="Web ACL ID for AWS WAF integration")
    logs_bucket: Optional[Any] = Field(None, description="S3 Bucket object (CDK construct) for loggging purposes")
    activate_additional_metrics: bool = Field(default=False, description="Whether to enable additional metrics for the Cloudfront distribution")

    route53: Route53Config = Field(..., description="Route 53 configuration for domain setup")

    class Typed:
        """Inner class, type-safe accessor for AWS CDK resources with proper typing.

        Provides strongly-typed access to AWS CDK resources for improved
        IDE support and type checking in CloudFront distribution configuration.
        """
        def __init__(self, config: 'CloudfrontConfig'):
            self._config = config

        @property
        def logs_bucket(self) -> 's3.IBucket':
            """S3 bucket for CloudFront access logs storage.

            Returns:
                Strongly-typed S3 bucket interface for logging configuration
            """
            return self._config.logs_bucket

    @property
    def typed(self) -> Typed:
        """Access to type-safe AWS CDK resource properties.

        Provides access to the Typed inner class for strongly-typed CDK resource
        references, improving IDE support and type checking capabilities.

        Returns:
            Typed accessor instance for CDK resource properties
        """
        if not hasattr(self, '_typed'):
            self._typed = self.Typed(self)
        return self._typed


    @field_validator("logs_bucket", mode="after")
    @classmethod
    def validate_logs_bucket(cls, value: Any) -> Any:
        """Validate S3 logs bucket CDK construct compatibility.

        Ensures the provided logs bucket object implements the required s3.IBucket
        interface for proper CloudFront logging integration and access control.

        Args:
            value: S3 bucket CDK construct for logging

        Returns:
            Validated S3 bucket construct or None if not provided

        Raises:
            ValueError: If bucket doesn't implement required interface
        """
        return cls.validate_bucket(value)

    @model_validator(mode="after")
    def validate_origins_structure(self) -> 'CloudfrontConfig':
        """Validate origins configuration structure and uniqueness constraints.

        Ensures the origins dictionary contains a required 'default' S3 origin
        and validates that all origin path patterns are unique to prevent
        routing conflicts in the CloudFront distribution configuration.

        Returns:
            Self after validation

        Raises:
            ValueError: If default S3 origin is missing, has wrong type, or path patterns conflict
        """
        if "default" not in self.origins:
            raise ValueError("'origins' must include a 'default' key for S3 bucket origin")

        default_origin = self.origins.get("default")
        if not isinstance(default_origin, S3OriginConfig):
            raise ValueError('Default origin must be an S3OriginConfig')

        # Validate path patterns don't conflict
        paths = []
        for key, origin in self.origins.items():
            if key != "default" and hasattr(origin, 'path'):
                paths.append(origin.path)

        if len(paths) != len(set(paths)):
            raise ValueError('Origin path patterns must be unique')

        return self

typed property

Access to type-safe AWS CDK resource properties.

Provides access to the Typed inner class for strongly-typed CDK resource references, improving IDE support and type checking capabilities.

Returns:

Type Description
Typed

Typed accessor instance for CDK resource properties

Typed

Inner class, type-safe accessor for AWS CDK resources with proper typing.

Provides strongly-typed access to AWS CDK resources for improved IDE support and type checking in CloudFront distribution configuration.

Source code in mare_aws_common_lib/models/cloudfront_config.py
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
class Typed:
    """Inner class, type-safe accessor for AWS CDK resources with proper typing.

    Provides strongly-typed access to AWS CDK resources for improved
    IDE support and type checking in CloudFront distribution configuration.
    """
    def __init__(self, config: 'CloudfrontConfig'):
        self._config = config

    @property
    def logs_bucket(self) -> 's3.IBucket':
        """S3 bucket for CloudFront access logs storage.

        Returns:
            Strongly-typed S3 bucket interface for logging configuration
        """
        return self._config.logs_bucket

logs_bucket property

S3 bucket for CloudFront access logs storage.

Returns:

Type Description
IBucket

Strongly-typed S3 bucket interface for logging configuration

validate_logs_bucket(value) classmethod

Validate S3 logs bucket CDK construct compatibility.

Ensures the provided logs bucket object implements the required s3.IBucket interface for proper CloudFront logging integration and access control.

Parameters:

Name Type Description Default
value Any

S3 bucket CDK construct for logging

required

Returns:

Type Description
Any

Validated S3 bucket construct or None if not provided

Raises:

Type Description
ValueError

If bucket doesn't implement required interface

Source code in mare_aws_common_lib/models/cloudfront_config.py
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
@field_validator("logs_bucket", mode="after")
@classmethod
def validate_logs_bucket(cls, value: Any) -> Any:
    """Validate S3 logs bucket CDK construct compatibility.

    Ensures the provided logs bucket object implements the required s3.IBucket
    interface for proper CloudFront logging integration and access control.

    Args:
        value: S3 bucket CDK construct for logging

    Returns:
        Validated S3 bucket construct or None if not provided

    Raises:
        ValueError: If bucket doesn't implement required interface
    """
    return cls.validate_bucket(value)

validate_origins_structure()

Validate origins configuration structure and uniqueness constraints.

Ensures the origins dictionary contains a required 'default' S3 origin and validates that all origin path patterns are unique to prevent routing conflicts in the CloudFront distribution configuration.

Returns:

Type Description
CloudfrontConfig

Self after validation

Raises:

Type Description
ValueError

If default S3 origin is missing, has wrong type, or path patterns conflict

Source code in mare_aws_common_lib/models/cloudfront_config.py
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
@model_validator(mode="after")
def validate_origins_structure(self) -> 'CloudfrontConfig':
    """Validate origins configuration structure and uniqueness constraints.

    Ensures the origins dictionary contains a required 'default' S3 origin
    and validates that all origin path patterns are unique to prevent
    routing conflicts in the CloudFront distribution configuration.

    Returns:
        Self after validation

    Raises:
        ValueError: If default S3 origin is missing, has wrong type, or path patterns conflict
    """
    if "default" not in self.origins:
        raise ValueError("'origins' must include a 'default' key for S3 bucket origin")

    default_origin = self.origins.get("default")
    if not isinstance(default_origin, S3OriginConfig):
        raise ValueError('Default origin must be an S3OriginConfig')

    # Validate path patterns don't conflict
    paths = []
    for key, origin in self.origins.items():
        if key != "default" and hasattr(origin, 'path'):
            paths.append(origin.path)

    if len(paths) != len(set(paths)):
        raise ValueError('Origin path patterns must be unique')

    return self
Example
from mare_aws_common_lib.models import CloudfrontConfig, S3OriginConfig, LoadBalancerOriginConfig, VpcOriginConfig, Route53Config

config = CloudfrontConfig(
    origins={
        # Required default S3 origin for static content
        "default": S3OriginConfig(
            name="static-assets",
            bucket=static_bucket,
            path="/assets",
            default_root_object="index.html"
        ),
        # API origin via Application Load Balancer
        "api": LoadBalancerOriginConfig(
            name="api-backend",
            path="/api/*",
            alb=api_alb,
            timeout=45
        ),
        # Private VPC origin for internal services
        "internal": VpcOriginConfig(
            name="internal-services",
            path="/internal/*",
            alb=api_alb,
            timeout=30
        )
    },
    ssl_certificate_id="12345678-1234-1234-1234-123456789012",
    web_acl_id="arn:aws:wafv2:us-east-1:123456789012:global/webacl/example/12345678-1234-1234-1234-123456789012",
    logs_bucket=logs_bucket,
    route53=Route53Config(
        hosted_zone_id="Z1234567890ABC",
        domain_name="mycompany.com"
    )

CloudfrontOrigin

CloudFront distributions support multiple origin types through a discriminated union:

S3OriginConfig

Bases: BaseModel, AwsTypesValidationMixin, PathValidationMixin, NameValidationMixin

Configuration model for CloudFront S3 bucket origin.

Defines the structure and validation rules for S3 bucket origins in CloudFront distributions, supporting static content delivery with configurable path patterns and default root object settings for web applications and content hosting.

Attributes:

Name Type Description
name str

Origin identifier for CloudFront distribution configuration

origin_type Literal['S3']

Fixed literal value identifying this as an S3 origin

bucket Any

S3 bucket CDK construct reference for content storage

path Optional[str]

Optional path pattern for content routing within the bucket

default_root_object str

Default file served for root requests to the origin

Source code in mare_aws_common_lib/models/cloudfront_config.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class S3OriginConfig(BaseModel, AwsTypesValidationMixin, PathValidationMixin, NameValidationMixin):
    """Configuration model for CloudFront S3 bucket origin.

    Defines the structure and validation rules for S3 bucket origins in CloudFront
    distributions, supporting static content delivery with configurable path patterns
    and default root object settings for web applications and content hosting.

    Attributes:
        name: Origin identifier for CloudFront distribution configuration
        origin_type: Fixed literal value identifying this as an S3 origin
        bucket: S3 bucket CDK construct reference for content storage
        path: Optional path pattern for content routing within the bucket
        default_root_object: Default file served for root requests to the origin
    """
    model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)

    name: str = Field(..., description="Origin identifier name")
    origin_type: Literal["S3"] = Field("S3", description="Must be S3_BUCKET")
    bucket: Any = Field(..., description="S3 Bucket object (CDK construct)")
    path: Optional[str] = Field(None, description="Path pattern for this origin")
    default_root_object: str = Field(default="index.html", description="Default root object for S3 origin")

    @field_validator("name")
    @classmethod
    def validate_origin_name(cls, value: str) -> str:
        """Validate the origin name using organizational naming standards.

        Applies origin-specific naming validation to ensure the name meets
        CloudFront origin identification requirements and organizational standards.

        Args:
            value: Raw origin name from configuration

        Returns:
            Validated origin name

        Raises:
            ValueError: If the origin name fails validation rules
        """
        return cls.validate_name(value, mode="ORIGIN")

    @field_validator("path")
    @classmethod
    def validate_path(cls, value: str) -> str:
        """Validate the path pattern format for S3 content routing.

        Ensures that any provided path pattern follows proper URL path conventions
        and CloudFront routing requirements for S3 bucket content access.

        Args:
            value: Raw path pattern from configuration

        Returns:
            Validated path pattern or None if not provided

        Raises:
            ValueError: If path pattern format is invalid
        """
        return cls.validate_path_pattern(value)

    @field_validator("bucket", mode="after")
    @classmethod
    def validate_s3_bucket(cls, value: Any) -> Any:
        """Validate S3 bucket CDK construct compatibility.

        Ensures the provided bucket object implements the required s3.IBucket
        interface for proper CloudFront origin integration and access control.

        Args:
            value: S3 bucket CDK construct

        Returns:
            Validated S3 bucket construct

        Raises:
            ValueError: If bucket doesn't implement required interface
        """
        return cls.validate_bucket(value)
validate_origin_name(value) classmethod

Validate the origin name using organizational naming standards.

Applies origin-specific naming validation to ensure the name meets CloudFront origin identification requirements and organizational standards.

Parameters:

Name Type Description Default
value str

Raw origin name from configuration

required

Returns:

Type Description
str

Validated origin name

Raises:

Type Description
ValueError

If the origin name fails validation rules

Source code in mare_aws_common_lib/models/cloudfront_config.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@field_validator("name")
@classmethod
def validate_origin_name(cls, value: str) -> str:
    """Validate the origin name using organizational naming standards.

    Applies origin-specific naming validation to ensure the name meets
    CloudFront origin identification requirements and organizational standards.

    Args:
        value: Raw origin name from configuration

    Returns:
        Validated origin name

    Raises:
        ValueError: If the origin name fails validation rules
    """
    return cls.validate_name(value, mode="ORIGIN")
validate_path(value) classmethod

Validate the path pattern format for S3 content routing.

Ensures that any provided path pattern follows proper URL path conventions and CloudFront routing requirements for S3 bucket content access.

Parameters:

Name Type Description Default
value str

Raw path pattern from configuration

required

Returns:

Type Description
str

Validated path pattern or None if not provided

Raises:

Type Description
ValueError

If path pattern format is invalid

Source code in mare_aws_common_lib/models/cloudfront_config.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@field_validator("path")
@classmethod
def validate_path(cls, value: str) -> str:
    """Validate the path pattern format for S3 content routing.

    Ensures that any provided path pattern follows proper URL path conventions
    and CloudFront routing requirements for S3 bucket content access.

    Args:
        value: Raw path pattern from configuration

    Returns:
        Validated path pattern or None if not provided

    Raises:
        ValueError: If path pattern format is invalid
    """
    return cls.validate_path_pattern(value)
validate_s3_bucket(value) classmethod

Validate S3 bucket CDK construct compatibility.

Ensures the provided bucket object implements the required s3.IBucket interface for proper CloudFront origin integration and access control.

Parameters:

Name Type Description Default
value Any

S3 bucket CDK construct

required

Returns:

Type Description
Any

Validated S3 bucket construct

Raises:

Type Description
ValueError

If bucket doesn't implement required interface

Source code in mare_aws_common_lib/models/cloudfront_config.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@field_validator("bucket", mode="after")
@classmethod
def validate_s3_bucket(cls, value: Any) -> Any:
    """Validate S3 bucket CDK construct compatibility.

    Ensures the provided bucket object implements the required s3.IBucket
    interface for proper CloudFront origin integration and access control.

    Args:
        value: S3 bucket CDK construct

    Returns:
        Validated S3 bucket construct

    Raises:
        ValueError: If bucket doesn't implement required interface
    """
    return cls.validate_bucket(value)
Example
from mare_aws_common_lib.models import S3OriginConfig

config = S3OriginConfig(
    name="static-assets",
    bucket=static_bucket,
    path="/assets",
    default_root_object="index.html"
)

LoadBalancerOriginConfig

Bases: BaseModel, AwsTypesValidationMixin, PathValidationMixin, NameValidationMixin

Configuration model for CloudFront Application Load Balancer origin.

Defines the structure and validation rules for ALB origins in CloudFront distributions, enabling dynamic content delivery through load balancer endpoints with configurable timeout settings and path-based routing.

Attributes:

Name Type Description
name str

Origin identifier for CloudFront distribution configuration

origin_type Literal['LOAD_BALANCER']

Fixed literal value identifying this as a load balancer origin

path str

Path pattern for routing requests to this origin (e.g., '/api/*')

alb Any

Application Load Balancer CDK construct reference

timeout int

Origin response timeout in seconds (1-180, warnings >60)

Source code in mare_aws_common_lib/models/cloudfront_config.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
class LoadBalancerOriginConfig(BaseModel, AwsTypesValidationMixin, PathValidationMixin, NameValidationMixin):
    """Configuration model for CloudFront Application Load Balancer origin.

    Defines the structure and validation rules for ALB origins in CloudFront
    distributions, enabling dynamic content delivery through load balancer
    endpoints with configurable timeout settings and path-based routing.

    Attributes:
        name: Origin identifier for CloudFront distribution configuration
        origin_type: Fixed literal value identifying this as a load balancer origin
        path: Path pattern for routing requests to this origin (e.g., '/api/*')
        alb: Application Load Balancer CDK construct reference
        timeout: Origin response timeout in seconds (1-180, warnings >60)
    """
    model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)

    name: str = Field(..., description="Origin identifier name")
    origin_type: Literal["LOAD_BALANCER"] = Field("LOAD_BALANCER", description="Must be LOAD_BALANCER")
    path: str = Field(..., description="Path pattern for this origin (e.g., '/api/*')")
    alb: Any = Field(..., description="Application Load Balancer object (CDK construct)")
    timeout: int = Field(default=30, description="How long Cloudfront waits for a response from the origin in seconds")

    @field_validator("name")
    @classmethod
    def validate_origin_name(cls, value: str) -> str:
        """Validate the origin name using organizational naming standards.

        Applies origin-specific naming validation to ensure the name meets
        CloudFront origin identification requirements and organizational standards.

        Args:
            value: Raw origin name from configuration

        Returns:
            Validated origin name

        Raises:
            ValueError: If the origin name fails validation rules
        """
        return cls.validate_name(value, mode="ORIGIN")

    @field_validator("path")
    @classmethod
    def validate_path(cls, value: str) -> str:
        """Validate the path pattern format for load balancer routing.

        Ensures the path pattern follows proper URL path conventions and
        CloudFront routing requirements for ALB backend integration.

        Args:
            value: Raw path pattern from configuration

        Returns:
            Validated path pattern

        Raises:
            ValueError: If path pattern format is invalid
        """
        return cls.validate_path_pattern(value)

    @field_validator("alb")
    @classmethod
    def validate_alb(cls, value: Any) -> Any:
        """Validate Application Load Balancer CDK construct compatibility.

        Ensures the provided ALB object implements the required interface
        for proper CloudFront origin integration and traffic forwarding.

        Args:
            value: Application Load Balancer CDK construct

        Returns:
            Validated ALB construct

        Raises:
            ValueError: If ALB doesn't implement required interface
        """
        return cls.validate_application_load_balancer(value)

    @field_validator("timeout")
    @classmethod
    def validate_timeout(cls, value: int) -> int:
        """Validate origin response timeout settings and AWS quota compliance.

        Ensures timeout values are within AWS CloudFront limits and provides
        warnings for values that require quota increase requests in the target
        AWS account for successful deployment.

        Args:
            value: Origin response timeout in seconds

        Returns:
            Validated timeout value

        Raises:
            ValueError: If timeout is outside allowed range (1-180 seconds)
        """
        if not (1 <= value <= 180):
            raise ValueError("'timeout' must be between 1 and 180 seconds")
        if value > 60:
            warnings.warn(
                f"⚠️ 'timeout' is set to {value}, which exceeds 60 seconds. This requires a limit increase request "
                "for the origin response timeout quota in the target AWS account."
            )
        return value
validate_alb(value) classmethod

Validate Application Load Balancer CDK construct compatibility.

Ensures the provided ALB object implements the required interface for proper CloudFront origin integration and traffic forwarding.

Parameters:

Name Type Description Default
value Any

Application Load Balancer CDK construct

required

Returns:

Type Description
Any

Validated ALB construct

Raises:

Type Description
ValueError

If ALB doesn't implement required interface

Source code in mare_aws_common_lib/models/cloudfront_config.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
@field_validator("alb")
@classmethod
def validate_alb(cls, value: Any) -> Any:
    """Validate Application Load Balancer CDK construct compatibility.

    Ensures the provided ALB object implements the required interface
    for proper CloudFront origin integration and traffic forwarding.

    Args:
        value: Application Load Balancer CDK construct

    Returns:
        Validated ALB construct

    Raises:
        ValueError: If ALB doesn't implement required interface
    """
    return cls.validate_application_load_balancer(value)
validate_origin_name(value) classmethod

Validate the origin name using organizational naming standards.

Applies origin-specific naming validation to ensure the name meets CloudFront origin identification requirements and organizational standards.

Parameters:

Name Type Description Default
value str

Raw origin name from configuration

required

Returns:

Type Description
str

Validated origin name

Raises:

Type Description
ValueError

If the origin name fails validation rules

Source code in mare_aws_common_lib/models/cloudfront_config.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@field_validator("name")
@classmethod
def validate_origin_name(cls, value: str) -> str:
    """Validate the origin name using organizational naming standards.

    Applies origin-specific naming validation to ensure the name meets
    CloudFront origin identification requirements and organizational standards.

    Args:
        value: Raw origin name from configuration

    Returns:
        Validated origin name

    Raises:
        ValueError: If the origin name fails validation rules
    """
    return cls.validate_name(value, mode="ORIGIN")
validate_path(value) classmethod

Validate the path pattern format for load balancer routing.

Ensures the path pattern follows proper URL path conventions and CloudFront routing requirements for ALB backend integration.

Parameters:

Name Type Description Default
value str

Raw path pattern from configuration

required

Returns:

Type Description
str

Validated path pattern

Raises:

Type Description
ValueError

If path pattern format is invalid

Source code in mare_aws_common_lib/models/cloudfront_config.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@field_validator("path")
@classmethod
def validate_path(cls, value: str) -> str:
    """Validate the path pattern format for load balancer routing.

    Ensures the path pattern follows proper URL path conventions and
    CloudFront routing requirements for ALB backend integration.

    Args:
        value: Raw path pattern from configuration

    Returns:
        Validated path pattern

    Raises:
        ValueError: If path pattern format is invalid
    """
    return cls.validate_path_pattern(value)
validate_timeout(value) classmethod

Validate origin response timeout settings and AWS quota compliance.

Ensures timeout values are within AWS CloudFront limits and provides warnings for values that require quota increase requests in the target AWS account for successful deployment.

Parameters:

Name Type Description Default
value int

Origin response timeout in seconds

required

Returns:

Type Description
int

Validated timeout value

Raises:

Type Description
ValueError

If timeout is outside allowed range (1-180 seconds)

Source code in mare_aws_common_lib/models/cloudfront_config.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
@field_validator("timeout")
@classmethod
def validate_timeout(cls, value: int) -> int:
    """Validate origin response timeout settings and AWS quota compliance.

    Ensures timeout values are within AWS CloudFront limits and provides
    warnings for values that require quota increase requests in the target
    AWS account for successful deployment.

    Args:
        value: Origin response timeout in seconds

    Returns:
        Validated timeout value

    Raises:
        ValueError: If timeout is outside allowed range (1-180 seconds)
    """
    if not (1 <= value <= 180):
        raise ValueError("'timeout' must be between 1 and 180 seconds")
    if value > 60:
        warnings.warn(
            f"⚠️ 'timeout' is set to {value}, which exceeds 60 seconds. This requires a limit increase request "
            "for the origin response timeout quota in the target AWS account."
        )
    return value
Example
from mare_aws_common_lib.models import LoadBalancerOriginConfig

config = LoadBalancerOriginConfig(
    name="api-backend",
    path="/api/*",
    alb=api_alb,
    timeout=45
)

VpcOriginConfig

Bases: BaseModel, AwsTypesValidationMixin, PathValidationMixin, NameValidationMixin

Configuration model for CloudFront VPC origin with private load balancer.

Defines the structure and validation rules for VPC-based origins in CloudFront distributions, enabling private network integration through VPC origins for secure communication with internal load balancers and services.

Attributes:

Name Type Description
name str

Origin identifier for CloudFront distribution configuration

origin_type Literal['VPC_ORIGIN']

Fixed literal value identifying this as a VPC origin

path str

Path pattern for routing requests to this origin (e.g., '/api/*')

alb Any

Application Load Balancer CDK construct reference within VPC

timeout int

Origin response timeout in seconds (1-180, warnings >60)

Source code in mare_aws_common_lib/models/cloudfront_config.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
class VpcOriginConfig(BaseModel, AwsTypesValidationMixin, PathValidationMixin, NameValidationMixin):
    """Configuration model for CloudFront VPC origin with private load balancer.

    Defines the structure and validation rules for VPC-based origins in CloudFront
    distributions, enabling private network integration through VPC origins for
    secure communication with internal load balancers and services.

    Attributes:
        name: Origin identifier for CloudFront distribution configuration
        origin_type: Fixed literal value identifying this as a VPC origin
        path: Path pattern for routing requests to this origin (e.g., '/api/*')
        alb: Application Load Balancer CDK construct reference within VPC
        timeout: Origin response timeout in seconds (1-180, warnings >60)
    """
    model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)

    name: str = Field(..., description="Origin identifier name")
    origin_type: Literal["VPC_ORIGIN"] = Field("VPC_ORIGIN", description="Must be VPC_ORIGIN")
    path: str = Field(..., description="Path pattern for this origin (e.g., '/api/*')")
    alb: Any = Field(..., description="Application Load Balancer object (CDK construct)")
    timeout: int = Field(default=30, description="How long Cloudfront waits for a response from the origin in seconds")

    @field_validator("name")
    @classmethod
    def validate_origin_name(cls, value: str) -> str:
        """Validate the origin name using organizational naming standards.

        Applies origin-specific naming validation to ensure the name meets
        CloudFront origin identification requirements and organizational standards.

        Args:
            value: Raw origin name from configuration

        Returns:
            Validated origin name

        Raises:
            ValueError: If the origin name fails validation rules
        """
        return cls.validate_name(value, mode="ORIGIN")

    @field_validator("path")
    @classmethod
    def validate_path(cls, value: str) -> str:
        """Validate the path pattern format for VPC origin routing.

        Ensures the path pattern follows proper URL path conventions and
        CloudFront routing requirements for VPC-based backend integration.

        Args:
            value: Raw path pattern from configuration

        Returns:
            Validated path pattern

        Raises:
            ValueError: If path pattern format is invalid
        """
        return cls.validate_path_pattern(value)

    @field_validator("alb")
    @classmethod
    def validate_alb(cls, value: Any) -> Any:
        """Validate Application Load Balancer CDK construct compatibility.

        Ensures the provided ALB object implements the required interface
        for proper CloudFront VPC origin integration and private traffic routing.

        Args:
            value: Application Load Balancer CDK construct

        Returns:
            Validated ALB construct

        Raises:
            ValueError: If ALB doesn't implement required interface
        """
        return cls.validate_application_load_balancer(value)

    @field_validator("timeout")
    @classmethod
    def validate_timeout(cls, value: int) -> int:
        """Validate origin response timeout settings and AWS quota compliance.

        Ensures timeout values are within AWS CloudFront limits and provides
        warnings for values that require quota increase requests in the target
        AWS account for successful deployment.

        Args:
            value: Origin response timeout in seconds

        Returns:
            Validated timeout value

        Raises:
            ValueError: If timeout is outside allowed range (1-180 seconds)
        """
        if not (1 <= value <= 180):
            raise ValueError("'timeout' must be between 1 and 180 seconds")
        if value > 60:
            warnings.warn(
                f"⚠️ 'timeout' is set to {value}, which exceeds 60 seconds. This requires a limit increase request "
                "for the origin response timeout quota in the target AWS account."
            )
        return value
validate_alb(value) classmethod

Validate Application Load Balancer CDK construct compatibility.

Ensures the provided ALB object implements the required interface for proper CloudFront VPC origin integration and private traffic routing.

Parameters:

Name Type Description Default
value Any

Application Load Balancer CDK construct

required

Returns:

Type Description
Any

Validated ALB construct

Raises:

Type Description
ValueError

If ALB doesn't implement required interface

Source code in mare_aws_common_lib/models/cloudfront_config.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
@field_validator("alb")
@classmethod
def validate_alb(cls, value: Any) -> Any:
    """Validate Application Load Balancer CDK construct compatibility.

    Ensures the provided ALB object implements the required interface
    for proper CloudFront VPC origin integration and private traffic routing.

    Args:
        value: Application Load Balancer CDK construct

    Returns:
        Validated ALB construct

    Raises:
        ValueError: If ALB doesn't implement required interface
    """
    return cls.validate_application_load_balancer(value)
validate_origin_name(value) classmethod

Validate the origin name using organizational naming standards.

Applies origin-specific naming validation to ensure the name meets CloudFront origin identification requirements and organizational standards.

Parameters:

Name Type Description Default
value str

Raw origin name from configuration

required

Returns:

Type Description
str

Validated origin name

Raises:

Type Description
ValueError

If the origin name fails validation rules

Source code in mare_aws_common_lib/models/cloudfront_config.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
@field_validator("name")
@classmethod
def validate_origin_name(cls, value: str) -> str:
    """Validate the origin name using organizational naming standards.

    Applies origin-specific naming validation to ensure the name meets
    CloudFront origin identification requirements and organizational standards.

    Args:
        value: Raw origin name from configuration

    Returns:
        Validated origin name

    Raises:
        ValueError: If the origin name fails validation rules
    """
    return cls.validate_name(value, mode="ORIGIN")
validate_path(value) classmethod

Validate the path pattern format for VPC origin routing.

Ensures the path pattern follows proper URL path conventions and CloudFront routing requirements for VPC-based backend integration.

Parameters:

Name Type Description Default
value str

Raw path pattern from configuration

required

Returns:

Type Description
str

Validated path pattern

Raises:

Type Description
ValueError

If path pattern format is invalid

Source code in mare_aws_common_lib/models/cloudfront_config.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
@field_validator("path")
@classmethod
def validate_path(cls, value: str) -> str:
    """Validate the path pattern format for VPC origin routing.

    Ensures the path pattern follows proper URL path conventions and
    CloudFront routing requirements for VPC-based backend integration.

    Args:
        value: Raw path pattern from configuration

    Returns:
        Validated path pattern

    Raises:
        ValueError: If path pattern format is invalid
    """
    return cls.validate_path_pattern(value)
validate_timeout(value) classmethod

Validate origin response timeout settings and AWS quota compliance.

Ensures timeout values are within AWS CloudFront limits and provides warnings for values that require quota increase requests in the target AWS account for successful deployment.

Parameters:

Name Type Description Default
value int

Origin response timeout in seconds

required

Returns:

Type Description
int

Validated timeout value

Raises:

Type Description
ValueError

If timeout is outside allowed range (1-180 seconds)

Source code in mare_aws_common_lib/models/cloudfront_config.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
@field_validator("timeout")
@classmethod
def validate_timeout(cls, value: int) -> int:
    """Validate origin response timeout settings and AWS quota compliance.

    Ensures timeout values are within AWS CloudFront limits and provides
    warnings for values that require quota increase requests in the target
    AWS account for successful deployment.

    Args:
        value: Origin response timeout in seconds

    Returns:
        Validated timeout value

    Raises:
        ValueError: If timeout is outside allowed range (1-180 seconds)
    """
    if not (1 <= value <= 180):
        raise ValueError("'timeout' must be between 1 and 180 seconds")
    if value > 60:
        warnings.warn(
            f"⚠️ 'timeout' is set to {value}, which exceeds 60 seconds. This requires a limit increase request "
            "for the origin response timeout quota in the target AWS account."
        )
    return value
Example
from mare_aws_common_lib.models import VpcOriginConfig

config = VpcOriginConfig(
    name="internal-services",
    path="/internal/*",
    alb=api_alb,
    timeout=30
)