Skip to content

Commit ef1212a

Browse files
committed
Reorder WAF rate rules
1 parent 07218c5 commit ef1212a

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

terraform/api_gateway.tf.json.template.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -298,48 +298,6 @@ def check_waf_rules(rules: JSONs) -> JSONs:
298298
'cloudwatch_metrics_enabled': True
299299
}
300300
},
301-
*[
302-
{
303-
'name': rate_limit.name,
304-
'statement': {
305-
'rate_based_statement': {
306-
'limit': rate_limit.value,
307-
'evaluation_window_sec': rate_limit.period,
308-
'aggregate_key_type': 'IP'
309-
}
310-
},
311-
'action': {
312-
'block': {
313-
'custom_response': {
314-
'response_code': 429,
315-
'response_header': [
316-
{
317-
'name': 'Retry-After',
318-
'value': str(rate_limit.retry_after)
319-
}
320-
]
321-
}
322-
}
323-
},
324-
'visibility_config': {
325-
'metric_name': rate_limit.name,
326-
'sampled_requests_enabled': True,
327-
'cloudwatch_metrics_enabled': True
328-
}
329-
}
330-
# We use two rate rules, one with a lower
331-
# threshold that will block requests, and one
332-
# with a higher threshold that will block
333-
# requests and trigger an alarm. Note, the rules
334-
# need to be defined in order of descending
335-
# threshold size since once a rate rule is
336-
# tripped, it will prevent evaluation of any
337-
# following rules.
338-
for rate_limit in [
339-
config.waf_rate_limit_alarm,
340-
config.waf_rate_limit,
341-
]
342-
],
343301
{
344302
'name': 'aws_common_rule_set',
345303
'statement': {
@@ -501,7 +459,49 @@ def check_waf_rules(rules: JSONs) -> JSONs:
501459
'cloudwatch_metrics_enabled': True
502460
}
503461
}
504-
])
462+
]),
463+
*[
464+
{
465+
'name': rate_limit.name,
466+
'statement': {
467+
'rate_based_statement': {
468+
'limit': rate_limit.value,
469+
'evaluation_window_sec': rate_limit.period,
470+
'aggregate_key_type': 'IP'
471+
}
472+
},
473+
'action': {
474+
'block': {
475+
'custom_response': {
476+
'response_code': 429,
477+
'response_header': [
478+
{
479+
'name': 'Retry-After',
480+
'value': str(rate_limit.retry_after)
481+
}
482+
]
483+
}
484+
}
485+
},
486+
'visibility_config': {
487+
'metric_name': rate_limit.name,
488+
'sampled_requests_enabled': True,
489+
'cloudwatch_metrics_enabled': True
490+
}
491+
}
492+
# We use two rate rules, one with a lower
493+
# threshold that will block requests, and one
494+
# with a higher threshold that will block
495+
# requests and trigger an alarm. Note, the rules
496+
# need to be defined in order of descending
497+
# threshold size since once a rate rule is
498+
# tripped, it will prevent evaluation of any
499+
# following rules.
500+
for rate_limit in [
501+
config.waf_rate_limit_alarm,
502+
config.waf_rate_limit,
503+
]
504+
]
505505
])
506506
]),
507507
'scope': 'REGIONAL',

0 commit comments

Comments
 (0)