CloudfrontDistributionBuilder¶
Bases: AbstractAWSResourceBuilder['CloudfrontDistributionBuilder', CloudfrontConfig]
AWS CDK builder for CloudFront distribution with multi-origin support.
Orchestrates the creation of a comprehensive CloudFront distribution supporting multiple origin types including S3 buckets for static content, Application Load Balancers for dynamic content, and VPC origins for private services. Provides global content delivery with SSL termination, WAF integration, and Route53 DNS management for production-ready web applications.
The builder creates: - CloudFront distribution with global edge caching - Multiple origins with path-based routing behaviors - SSL certificate integration (us-east-1 requirement) - Route53 A record for domain routing - CloudWatch logging configuration - WAF Web ACL integration for security - Origin Access Control for S3 bucket security
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
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 91 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 197 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 303 304 305 306 307 308 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 | |
Attributes¶
_resource_type = AWSResourceType.CLOUDFRONT
class-attribute
instance-attribute
¶
Functions¶
_add_lb_origin(origin_cfg)
¶
Add Application Load Balancer origin with dynamic content behavior.
Creates a CloudFront behavior for ALB-based origins with caching disabled for dynamic content, HTTPS-only viewer protocol, and configurable timeout settings for API and application server integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_cfg
|
LoadBalancerOriginConfig
|
Load balancer origin configuration with path and timeout settings |
required |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
_add_vpc_origin(origin_cfg)
¶
Add VPC origin with private network integration behavior.
Creates a CloudFront behavior for VPC-based origins enabling private network access through VPC origin configuration with ALB integration, caching disabled for dynamic content, and secure HTTPS communication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_cfg
|
VpcOriginConfig
|
VPC origin configuration with path and timeout settings |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, BehaviorOptions]
|
Tuple containing path pattern and behavior configuration |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
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 | |
_control_consistency()
¶
Validate builder state and configuration consistency.
Performs pre-build validation to ensure all required configurations are present and the builder state is consistent for successful CloudFront distribution deployment with proper DNS integration.
Raises:
| Type | Description |
|---|---|
ValueError
|
If Route53 configuration is missing |
ValidationError
|
If configuration validation fails |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
_create_route53_a_record(scope)
¶
Create Route53 A record pointing to the CloudFront distribution.
Creates an alias A record that routes DNS queries for the configured domain to the CloudFront distribution edge locations for global content delivery and improved performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
CDK construct scope for resource creation |
required |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
_get_route53_hosted_zone(scope)
¶
Retrieve Route53 hosted zone reference for DNS record management.
Creates a reference to the existing Route53 hosted zone for creating DNS records that route traffic to the CloudFront distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
CDK construct scope for resource reference |
required |
Returns:
| Type | Description |
|---|---|
HostedZone
|
Route53 hosted zone reference |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
_get_ssl_certificate(scope)
¶
Retrieve SSL certificate reference for CloudFront HTTPS termination.
Creates a reference to the existing ACM certificate located in us-east-1 region as required by CloudFront for global SSL/TLS termination at edge locations worldwide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
CDK construct scope for resource reference |
required |
Returns:
| Type | Description |
|---|---|
ICertificate
|
ACM certificate reference for HTTPS configuration |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
_get_static_files_origin(origin_cfg)
¶
Configure S3 bucket origin for static content delivery.
Creates the default behavior for S3-based static content with Origin Access Control for security, optimized caching for performance, and HTTPS redirect for secure content delivery. Serves as the fallback origin for the distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_cfg
|
S3OriginConfig
|
S3 origin configuration with bucket and path settings |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, BehaviorOptions, str]
|
Tuple containing path, behavior options, and default root object |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
_set_config()
¶
Validate and set the CloudFront configuration from builder inputs.
Combines the builder configuration with Route53 parameters to create a validated CloudfrontConfig instance, ensuring all required fields and validation rules are satisfied for successful deployment.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the combined configuration fails validation |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
build(scope)
¶
Build the complete CloudFront distribution infrastructure.
Creates and configures the CloudFront distribution with all specified origins, behaviors, security settings, and DNS integration. Establishes global content delivery with proper caching policies and origin routing for multi-tier applications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
CDK construct scope for resource creation |
required |
Returns:
| Type | Description |
|---|---|
Distribution
|
CloudFront distribution instance for the deployed service |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If configuration validation fails |
ValueError
|
If required configurations are missing |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
80 81 82 83 84 85 86 87 88 89 90 91 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 | |
reset()
¶
Reset builder state and clear configuration data.
Initializes the builder for a new build cycle by clearing all configuration data and resetting internal state to default values.
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
40 41 42 43 44 45 46 47 48 | |
set_builder_config(config)
¶
Configure core CloudFront distribution settings and origins.
Sets the main configuration including origins, SSL certificates, WAF settings, and logging configuration for the CloudFront distribution deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
CloudFront configuration with origins, certificates, and security settings |
required |
Returns:
| Type | Description |
|---|---|
CloudfrontDistributionBuilder
|
Builder instance for method chaining |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
set_route53_config(config)
¶
Configure Route53 DNS settings for the CloudFront distribution.
Sets the hosted zone and domain configuration required for creating DNS records that route traffic to the CloudFront distribution edge locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Route53 configuration containing hosted_zone_id and domain_name |
required |
Returns:
| Type | Description |
|---|---|
CloudfrontDistributionBuilder
|
Builder instance for method chaining |
Source code in mare_aws_common_lib/builders/cloudfront_builder.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |