WafBuilder¶
Bases: AbstractAWSResourceBuilder['WafBuilder', WafConfig]
AWS WAF (Web Application Firewall) builder for CloudFront distribution protection.
Creates a comprehensive WAF v2 Web ACL configured with AWS Managed Rules and custom rate limiting to protect CloudFront distributions from common web exploits, malicious traffic, and automated attacks. Implements organizational security standards with built-in monitoring, metrics collection, and cross-stack integration.
Source code in mare_aws_common_lib/builders/waf_builder.py
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 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 | |
Attributes¶
_requires_builder_config = False
class-attribute
instance-attribute
¶
_resource_type = AWSResourceType.WAF
class-attribute
instance-attribute
¶
Functions¶
_control_consistency()
¶
Validate builder configuration and internal state consistency. Perform consistency checks and configuration validation before build.
Validates the WafConfig using Pydantic models to ensure all required fields are present and valid.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If configuration validation fails. Error details are printed to console for debugging. |
Source code in mare_aws_common_lib/builders/waf_builder.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
_create_rule_action_overrides(overrides)
¶
Create WAF rule action overrides from configuration dictionary.
Transforms the configuration dictionary of rule overrides into WAF-compatible rule action override properties. This allows fine-tuning of individual rules within AWS Managed Rule Groups by specifying custom actions (allow, block, count) that override the default rule group behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overrides
|
Dict[str, RuleActionType]
|
Dictionary mapping rule names to desired action types. Keys are rule names as strings, values are RuleActionType enums. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
List of RuleActionOverrideProperty objects ready for WAF configuration. Returns empty list if no overrides are provided or if the input is None. |
Source code in mare_aws_common_lib/builders/waf_builder.py
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 | |
_create_web_acl(scope)
¶
Build and deploy the WAF Web ACL with comprehensive security rules.
Creates a complete WAF v2 Web ACL configured for CloudFront protection with multiple AWS Managed Rule groups and custom rate limiting. Automatically stores the Web ACL ARN in Parameter Store for cross-stack integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
CDK construct scope for resource creation |
required |
Returns:
| Type | Description |
|---|---|
CfnWebACL
|
wafv2.CfnWebACL: The created WAF Web ACL resource with all configured rules |
Source code in mare_aws_common_lib/builders/waf_builder.py
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 | |
_set_config()
¶
Create and validate the WAF configuration from builder config.
Parses and validates the provided builder configuration against the WafConfig model schema using Pydantic validation.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the builder configuration is invalid, missing required fields, or contains values that don't conform to the WafConfig model schema. |
Source code in mare_aws_common_lib/builders/waf_builder.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
build(scope)
¶
Build and deploy the complete WAF Web ACL infrastructure.
Orchestrates the creation of a comprehensive WAF v2 Web ACL with multiple security rule groups and automatically stores the resulting ARN in Parameter Store for cross-stack integration. This method serves as the main entry point for WAF deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
CDK construct scope for resource creation and dependency management |
required |
Returns:
| Type | Description |
|---|---|
CfnWebACL
|
wafv2.CfnWebACL: The created WAF Web ACL resource with all configured rules |
Source code in mare_aws_common_lib/builders/waf_builder.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
reset()
¶
Reset the builder state to initial configuration.
Clears any previous build state and prepares the builder for a new WAF Web ACL creation. Inherits base reset functionality from the abstract parent class.
Called automatically before each build operation to ensure clean state and prevent cross-contamination between multiple WAF deployments.
Source code in mare_aws_common_lib/builders/waf_builder.py
23 24 25 26 27 28 29 30 31 32 33 | |