AWS WAF Rule
This page shows how to write Terraform and CloudFormation for AWS WAF Rule and write them securely.
aws_waf_rule (Terraform)
The Rule in AWS WAF can be configured in Terraform with the resource name aws_waf_rule. The following sections describe 1 example of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_waf_rule" "sql_injection_rule" {
count = var.sql_injection ? 1 : 0
depends_on = ["aws_waf_sql_injection_match_set.sql_injection_set"]
name = "SQL Injection Rule"
metric_name = "SQLInjectionRule"
Parameters
-
arnoptional computed - string -
idoptional computed - string -
metric_namerequired - string -
namerequired - string -
tagsoptional - map from string to string -
predicatesset block
Explanation in Terraform Registry
Provides a WAF Rule Resource
AWS::WAF::Rule (CloudFormation)
The Rule in WAF can be configured in CloudFormation with the resource name AWS::WAF::Rule. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: 'AWS::WAF::Rule'
XssRule:
Properties:
Name: !Join
- ''
- - !Ref WebAppACL
Type: 'AWS::WAF::Rule'
XssRule:
Properties:
Name: !Join
- ''
- - !Ref WebAppACL
Type: AWS::WAF::Rule
Properties:
Name: IpBlacklist
MetricName: IpBlacklist
Predicates:
- DataId: !Ref IpBlacklistIpSet
Type: AWS::WAF::Rule
Condition: isGlobal
Properties:
MetricName: !Join ['', [!Ref stackPrefix, 'mitigatesqli']]
Name: !Join ['-', [!Ref stackPrefix, 'mitigate-sqli']]
Predicates:
Type: 'AWS::WAF::Rule'
Properties:
Name: !Join [' - ', [!Ref 'AWS::StackName', 'Whitelist Rule']]
MetricName: !Join ['', [!Join ['', !Split ['-', !Ref 'AWS::StackName']], 'WhitelistRule']]
Predicates:
- DataId: !Ref WAFWhitelistSet
"Type": "AWS::WAF::Rule"
},
"XssRule": {
"Properties": {
"Name": { "Fn::Join" : [ "", [{"Ref" : "WebACLName"}, "XssRule"]] },
"MetricName": { "Fn::Join" : [ "", [{"Ref" : "WebACLName"}, "XssRule"]]},
"Type": "AWS::WAF::Rule"
},
"XssRule": {
"Properties": {
"Name": { "Fn::Join" : [ "", [{"Ref" : "WebACLName"}, "XssRule"]] },
"MetricName": { "Fn::Join" : [ "", [{"Ref" : "WebACLName"}, "XssRule"]]},
"Type": "AWS::WAF::Rule"
},
"XssRule": {
"Properties": {
"Name": { "Fn::Join" : [ "", [{"Ref" : "WebACLName"}, "XssRule"]] },
"MetricName": { "Fn::Join" : [ "", [{"Ref" : "WebACLName"}, "XssRule"]]},
"Type": "AWS::WAF::Rule"
},
"XssRule": {
"Properties": {
"Name": {
"Fn::Join": [
"Type": "AWS::WAF::Rule"
},
"XssRule": {
"Properties": {
"Name": {
"Fn::Join": [
Parameters
-
MetricNamerequired - String -
Namerequired - String -
Predicatesoptional - List of Predicate
Explanation in CloudFormation Registry
Note This is AWS WAF Classic documentation. For more information, see AWS WAF Classic in the developer guide. For the latest version of AWS WAF , use the AWS WAFV2 API and see the AWS WAF Developer Guide. With the latest version, AWS WAF has a single set of endpoints for regional and global use. A combination of
ByteMatchSet,IPSet, and/orSqlInjectionMatchSetobjects that identify the web requests that you want to allow, block, or count. For example, you might create aRulethat includes the following predicates:+ AnIPSetthat causes AWS WAF to search for web requests that originate from the IP address192.0.2.44+ AByteMatchSetthat causes AWS WAF to search for web requests for which the value of theUser-Agentheader isBadBot.To match the settings in this
Rule, a request must originate from192.0.2.44AND include aUser-Agentheader for which the value isBadBot.
Frequently asked questions
What is AWS WAF Rule?
AWS WAF Rule is a resource for WAF of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS WAF Rule?
For Terraform, the DNXLabs/terraform-aws-waf source code example is useful. See the Terraform Example section for further details.
For CloudFormation, the divuu/CloudFormation-Scripts, ade-mola/Deploy-Web-App-Using-CloudFormation and PRX/Infrastructure source code examples are useful. See the CloudFormation Example section for further details.