AWS WAF V2 Regex Pattern Set

This page shows how to write Terraform and CloudFormation for AWS WAF V2 Regex Pattern Set and write them securely.

aws_wafv2_regex_pattern_set (Terraform)

The Regex Pattern Set in AWS WAF V2 can be configured in Terraform with the resource name aws_wafv2_regex_pattern_set. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

WAF.tf#L3
resource "aws_wafv2_regex_pattern_set" "invalid_url" {
  name        = "invalid_url"
  scope       = "REGIONAL"

  regular_expression {
    regex_string = "admin"
waf.tf#L59
resource "aws_wafv2_regex_pattern_set" "blockedURL"{
    name = "blocked-URL"
    scope = "REGIONAL"

    # blocks of regular expression patterns that you want AWS WAF to search for
    regular_expression {
waf.tf#L1
resource "aws_wafv2_regex_pattern_set" "deny_eb_cname_regex" {
  name        = "eb-cnames"
  description = "EB CNAME regex pattern set"
  scope       = "REGIONAL"

  regular_expression {
waf.tf#L59
resource "aws_wafv2_regex_pattern_set" "blockedURL"{
    name = "blocked-URL"
    scope = "REGIONAL"

    # blocks of regular expression patterns that you want AWS WAF to search for
    regular_expression {
main.tf#L7
resource "aws_wafv2_regex_pattern_set" "this" {
  description = var.description
  name        = var.name
  scope       = var.scope
  tags        = var.tags

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an AWS WAFv2 Regex Pattern Set Resource

AWS::WAFv2::RegexPatternSet (CloudFormation)

The RegexPatternSet in WAFv2 can be configured in CloudFormation with the resource name AWS::WAFv2::RegexPatternSet. The following sections describe 9 examples of how to use the resource and its parameters.

Example Usage from GitHub

product.template-ap-southeast-1.yaml#L9
    Type: AWS::WAFv2::RegexPatternSet
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-regexpatternset.html
    Properties:
      Scope: !Ref 'Scope'
Outputs:
  Arn:
product.template-eu-west-3.yaml#L9
    Type: AWS::WAFv2::RegexPatternSet
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-regexpatternset.html
    Properties:
      Scope: !Ref 'Scope'
Outputs:
  Arn:
product.template-us-east-2.yaml#L9
    Type: AWS::WAFv2::RegexPatternSet
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-regexpatternset.html
    Properties:
      Scope: !Ref 'Scope'
Outputs:
  Arn:
product.template-eu-central-1.yaml#L9
    Type: AWS::WAFv2::RegexPatternSet
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-regexpatternset.html
    Properties:
      Scope: !Ref 'Scope'
Outputs:
  Arn:
product.template-eu-north-1.yaml#L9
    Type: AWS::WAFv2::RegexPatternSet
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-regexpatternset.html
    Properties:
      Scope: !Ref 'Scope'
Outputs:
  Arn:
template.json#L411
    "AWS::WAFv2::RegexPatternSet": {
      "Type": "AWS::WAFv2::RegexPatternSet",
      "Properties": {}
    },
    "AWS::Batch::JobDefinition": {
      "Type": "AWS::Batch::JobDefinition",
WAFv2RegexPatternSetSpecification.json#L22
    "AWS::WAFv2::RegexPatternSet": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-regexpatternset.html",
      "Properties": {
        "Description": {
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-regexpatternset.html#cfn-wafv2-regexpatternset-description",
          "UpdateType": "Mutable",
wafv2.json#L20
      "Type": "AWS::WAFv2::RegexPatternSet",
      "Properties": {
        "Description": "Regex Pattern Set for the Bots",
        "Name": "Bots",
        "RegularExpressionList": [
          "^.+(guzzlehttp|trovitbot|phantomjs|wget).+"
awsResouceIconMatches.json#L1921
        "resourceType": "AWS::WAFv2::RegexPatternSet",
        "filePath": null
      },
      {
        "resourceType": "AWS::WAFv2::IPSet",
        "filePath": null

Parameters

Explanation in CloudFormation Registry

Note This is the latest version of AWS WAF, named AWS WAFV2, released in November, 2019. For information, including how to migrate your AWS WAF resources from the prior release, see the AWS WAF Developer Guide. Use a RegexPatternSet to have AWS WAF inspect a web request component for a specific set of regular expression patterns. You use a regex pattern set by providing its Amazon Resource Name (ARN) to the rule statement RegexPatternSetReferenceStatement, when you add a rule to a rule group or web ACL.

Frequently asked questions

What is AWS WAF V2 Regex Pattern Set?

AWS WAF V2 Regex Pattern Set is a resource for WAF V2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS WAF V2 Regex Pattern Set?

For Terraform, the javyak/nw_public_cloud, ipspace/pubcloud and mikeapted/tf-shared-alb-rules-waf source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the awslabs/aws-service-catalog-products, awslabs/aws-service-catalog-products and awslabs/aws-service-catalog-products source code examples are useful. See the CloudFormation Example section for further details.