AWS-WAF

Amazon Web Services Web Application Firewall (WAF).

Network Security · AWS WAF

Details

IDAWS-WAF
ProviderAmazon
CategoryNetwork Security
From Version6.5.0
Docker Imagedemisto/boto3py3:1.0.0.10221838
Supported ModulesAgentix XSIAM

README

Amazon Web Services Web Application Firewall (WAF)

Configure AWS-WAF in Cortex

Parameter Description Required
Role Arn   False
Role Session Name   False
AWS Default Region   True
Role Session Duration   False
Access Key   False
Secret Key   False
Timeout The time in seconds until a timeout exception is reached. You can specify just the read timeout (for example 60) or also the connect timeout followed after a comma (for example 60,10). If a connect timeout is not specified, a default of 10 second will be used. False
Retries The maximum number of retry attempts when connection or throttling errors are encountered. Set to 0 to disable retries. The default value is 5 and the limit is 10. Note: Increasing the number of retries will increase the execution time. False
Trust any certificate (not secure)   False
Use system proxy settings   False

Commands

You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

aws-waf-ip-set-create


Create a new IP set.

Base Command

aws-waf-ip-set-create

Input

Argument Name Description Required
name The IP set name. Required
scope The IP set scope. Possible values are: Global, Regional. Default is Regional. Optional
addresses A comma-separated list of the IP set addresses in CIDR notation. Optional
description The IP set description. Optional
ip_version The IP set versions. Possible values are: IPV4, IPV6. Required
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
tag_key A comma-separated list of the keys of the tags to associate with the IP set. Optional
tag_value A comma-separated list of the values of the tags to associate with the IP set. Optional

Context Output

Path Type Description
AWS.Waf.IpSet.Id String The IP set ID.
AWS.Waf.IpSet.Name String The IP set name.
AWS.Waf.IpSet.Description String The IP set description.
AWS.Waf.IpSet.LockToken String The IP set lock token.
AWS.Waf.IpSet.ARN String The IP set Amazon Resource Name.

Command example

!aws-waf-ip-set-create ip_version=IPV4 name=name addresses="1.1.1.1/32"

Context Example

{
    "AWS": {
        "Waf": {
            "IpSet": {
                "ARN": "arn",
                "Description": "",
                "Id": "id",
                "LockToken": "lockToken",
                "Name": "name"
            }
        }
    }
}

Human Readable Output

AWS Waf ip set with id id was created successfully

aws-waf-ip-set-get


Get a specific IP set.

Base Command

aws-waf-ip-set-get

Input

Argument Name Description Required
name The IP set name. Required
scope The IP set scope. Possible values are: Global, Regional. Default is Regional. Optional
id The IP set ID. Required
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

Path Type Description
AWS.Waf.IpSet.Id String The IP set ID.
AWS.Waf.IpSet.Name String The IP set name.
AWS.Waf.IpSet.Description String The IP set description.
AWS.Waf.IpSet.IPAddressVersion String The IP set IP version.
AWS.Waf.IpSet.Addresses String The IP set IP addresses.
AWS.Waf.IpSet.ARN String The IP set Amazon Resource Name.

Command example

!aws-waf-ip-set-get id=id name=name

Context Example

{
    "AWS": {
        "Waf": {
            "IpSet": {
                "ARN": "arn",
                "Addresses": [
                    "1.1.2.2/32"
                ],
                "Description": "",
                "IPAddressVersion": "IPV4",
                "Id": "id",
                "Name": "name"
            }
        }
    }
}

Human Readable Output

IP Set

ARN Addresses Description IPAddressVersion Id Name
arn 1.1.2.2/32   IPV4 id name

aws-waf-ip-set-update


Update an IP set.

Base Command

aws-waf-ip-set-update

Input

Argument Name Description Required
name The IP set name. Required
scope The IP set scope. Possible values are: Global, Regional. Default is Regional. Optional
id The IP set ID. Required
addresses A comma-separated list of the IP set addresses in CIDR notation. Required
description The IP set description. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
is_overwrite Whether to overwrite the existing addresses. Possible values are: true, false. Default is false. Optional

Context Output

There is no context output for this command.

aws-waf-ip-set-list


Lists IP sets.

Base Command

aws-waf-ip-set-list

Input

Argument Name Description Required
scope The IP set scope. Possible values are: Global, Regional. Default is Regional. Optional
next_token The token for the next page. Optional
limit The maximum number of results to return. Default is 50. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

Path Type Description
AWS.Waf.IpSet.Id String The IP set ID.
AWS.Waf.IpSet.Name String The IP set name.
AWS.Waf.IpSet.Description String The IP set description.
AWS.Waf.IpSet.LockToken String The IP set lock token.
AWS.Waf.IpSet.ARN unknown The IP set Amazon Resource Name.
AWS.Waf.IpSetNextToken String The token for the next page.

Command example


#### Context Example

```json
{
    "AWS": {
        "Waf": {
            "IpSet": [
                {
                    "ARN": "arn",
                    "Description": "",
                    "Id": "id",
                    "LockToken": "lockToken",
                    "Name": "name"
                },
                {
                    "ARN": "arn",
                    "Description": "",
                    "Id": "id1",
                    "LockToken": "lockToken1",
                    "Name": "name1"
                }
            ],
            "IpSetNextToken": "sdf"
        }
    }
}

Human Readable Output

List IP Sets

Name Id ARN Description
name id arn  
name1 id1 arn  

aws-waf-ip-set-delete


Delete a specific IP set.

Base Command

aws-waf-ip-set-delete

Input

Argument Name Description Required
name The IP set name. Required
scope The IP set scope. Possible values are: Global, Regional. Default is Regional. Optional
id The IP set ID. Required
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

There is no context output for this command.

aws-waf-regex-set-create


Create a new regex set.

Base Command

aws-waf-regex-set-create

Input

Argument Name Description Required
name The regex set name. Required
scope The regex set scope. Possible values are: Global, Regional. Default is Regional. Optional
regex_pattern A comma-separated list of the regex patterns. Required
description The regex set description. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
tag_key A comma-separated list of the keys of the tags to associate with the regex set. Optional
tag_value A comma-separated list of the values of the tags to associate with the regex set. Optional

Context Output

Path Type Description
AWS.Waf.RegexSet.Id String The regex set ID.
AWS.Waf.RegexSet.Name String The regex set name.
AWS.Waf.RegexSet.Description String The regex set description.
AWS.Waf.RegexSet.LockToken String The regex set lock token.
AWS.Waf.RegexSet.ARN String The regex set Amazon Resource Name.

Command example

!aws-waf-regex-set-create name=name regex_pattern="pattern"

Context Example

{
    "AWS": {
        "Waf": {
            "RegexSet": {
                "ARN": "arn",
                "Description": "",
                "Id": "id",
                "LockToken": "lockToken",
                "Name": "name"
            }
        }
    }
}

Human Readable Output

AWS Waf regex set with id id was created successfully

aws-waf-regex-set-get


Get a specific regex set.

Base Command

aws-waf-regex-set-get

Input

Argument Name Description Required
name The regex set name. Required
scope The regex set scope. Possible values are: Global, Regional. Default is Regional. Optional
id The regex set ID. Required
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

Path Type Description
AWS.Waf.RegexSet.Id String The regex set ID.
AWS.Waf.RegexSet.Name String The regex set name.
AWS.Waf.RegexSet.Description String The regex set description.
AWS.Waf.RegexSet.RegularExpressionList String The regex set patterns list.
AWS.Waf.RegexSet.ARN String The regex set Amazon Resource Name.

Command example

!aws-waf-regex-set-get id=id name=name

Context Example

{
    "AWS": {
        "Waf": {
            "RegexSet": {
                "ARN": "arn",
                "Description": "",
                "Id": "id",
                "Name": "name",
                "RegularExpressionList": [
                    {
                        "RegexString": "^dog"
                    }
                ]
            }
        }
    }
}

Human Readable Output

Regex Set

ARN Description Id Name RegularExpressionList
arn   id name {‘RegexString’: ‘^dog’}

aws-waf-regex-set-update


Update a regex set.

Base Command

aws-waf-regex-set-update

Input

Argument Name Description Required
name The regex set name. Required
scope The regex set scope. Possible values are: Global, Regional. Default is Regional. Optional
id The regex set ID. Required
regex_pattern A comma-separated list of the regex patterns. Required
description The regex set description. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
is_overwrite Whether to overwrite the existing regex patterns. Possible values are: true, false. Default is false. Optional

Context Output

There is no context output for this command.

aws-waf-regex-set-list


Lists regex sets.

Base Command

aws-waf-regex-set-list

Input

Argument Name Description Required
scope The regex set scope. Possible values are: Global, Regional. Default is Regional. Optional
next_token The token for the next page. Optional
limit The maximum number of results to return. Default is 50. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

Path Type Description
AWS.Waf.RegexSet.Id String The regex set ID.
AWS.Waf.RegexSet.Name String The regex set name.
AWS.Waf.RegexSet.Description String The regex set description.
AWS.Waf.RegexSet.LockToken String The regex set lock token.
AWS.Waf.RegexSet.RegexPatternSets.ARN unknown The regex set Amazon Resource Name.
AWS.Waf.RegexSetNextToken String The token for the next page.

Command example


#### Context Example

```json
{
    "AWS": {
        "Waf": {
            "RegexSet": [
                {
                    "ARN": "arn",
                    "Description": "",
                    "Id": "id",
                    "LockToken": "lockToken",
                    "Name": "name"
                },
                {
                    "ARN": "arn",
                    "Description": "",
                    "Id": "id1",
                    "LockToken": "lockToken1",
                    "Name": "name1"
                }
            ],
            "RegexSetNextToken": "name"
        }
    }
}

Human Readable Output

List regex Sets

Name Id ARN Description
name id arn  
name1 id1 arn  

aws-waf-regex-set-delete


Delete a specific regex set.

Base Command

aws-waf-regex-set-delete

Input

Argument Name Description Required
name The regex set name. Required
scope The regex set scope. Possible values are: Global, Regional. Default is Regional. Optional
id The regex set ID. Required
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

There is no context output for this command.

aws-waf-rule-group-list


Lists rule groups.

Base Command

aws-waf-rule-group-list

Input

Argument Name Description Required
scope The rule group scope. Possible values are: Global, Regional. Default is Regional. Optional
next_token The token for the next page. Optional
limit The maximum number of results to return. Default is 50. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

Path Type Description
AWS.Waf.RuleGroup.Id String The rule group ID.
AWS.Waf.RuleGroup.Name String The rule group name.
AWS.Waf.RuleGroup.Description String The rule group description.
AWS.Waf.RuleGroup.LockToken String The rule group lock token.
AWS.Waf.RuleGroup.ARN unknown The rule group Amazon Resource Name.
AWS.Waf.RuleGroupNextToken String The token for the next page.

Command example


#### Context Example

```json
{
    "AWS": {
        "Waf": {
            "RuleGroup": [
                {
                    "ARN": "arn",
                    "Description": "",
                    "Id": "id",
                    "LockToken": "lockToken",
                    "Name": "name"
                },
                {
                    "ARN": "arn",
                    "Description": "",
                    "Id": "id1",
                    "LockToken": "lockToken1",
                    "Name": "name1"
                }
            ],
            "RuleGroupNextToken": "name"
        }
    }
}

Human Readable Output

List rule groups

Name Id ARN Description
name id arn  
name1 id1 arn  

aws-waf-rule-group-get


Get a specific rule group.

Base Command

aws-waf-rule-group-get

Input

Argument Name Description Required
name The rule group name. Required
scope The rule group scope. Possible values are: Global, Regional. Default is Regional. Optional
id The rule group ID. Required
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

Path Type Description
AWS.Waf.RuleGroup.Id String The rule group ID.
AWS.Waf.RuleGroup.Name String The rule group name.
AWS.Waf.RuleGroup.Description String The rule group description.
AWS.Waf.RuleGroup.Rules String The rule group rules.
AWS.Waf.RuleGroup.ARN String The rule group Amazon Resource Name.

Command example

!aws-waf-rule-group-get id=id name=name

Context Example

{
    "AWS": {
        "Waf": {
            "RuleGroup": {
                "ARN": "arn",
                "Capacity": 1500,
                "Description": "",
                "Id": "id",
                "LabelNamespace": "LabelNamespace",
                "Name": "name",
                "Rules": [
                    {
                        "Action": {
                            "Allow": {}
                        },
                        "Name": "name",
                        "Priority": 1,
                        "Statement": {
                            "AndStatement": {
                                "Statements": [
                                    {
                                        "ByteMatchStatement": {
                                            "FieldToMatch": {
                                                "Body": {
                                                    "OversizeHandling": "CONTINUE"
                                                }
                                            },
                                            "PositionalConstraint": "CONTAINS_WORD",
                                            "SearchString": "ssss",
                                            "TextTransformations": [
                                                {
                                                    "Priority": 0,
                                                    "Type": "BASE64_DECODE_EXT"
                                                }
                                            ]
                                        }
                                    },
                                    {
                                        "ByteMatchStatement": {
                                            "FieldToMatch": {
                                                "Body": {
                                                    "OversizeHandling": "CONTINUE"
                                                }
                                            },
                                            "PositionalConstraint": "CONTAINS_WORD",
                                            "SearchString": "fyfyu",
                                            "TextTransformations": [
                                                {
                                                    "Priority": 0,
                                                    "Type": "BASE64_DECODE_EXT"
                                                }
                                            ]
                                        }
                                    }
                                ]
                            }
                        },
                        "VisibilityConfig": {
                            "CloudWatchMetricsEnabled": true,
                            "MetricName": "Hey_Test",
                            "SampledRequestsEnabled": true
                        }
                    },
                    {
                        "Action": {
                            "Allow": {}
                        },
                        "Name": "name1",
                        "Priority": 2,
                        "Statement": {
                            "AndStatement": {
                                "Statements": [
                                    {
                                        "IPSetReferenceStatement": {
                                            "ARN": "arn"
                                        }
                                    },
                                    {
                                        "IPSetReferenceStatement": {
                                            "ARN": "arn"
                                        }
                                    },
                                    {
                                        "IPSetReferenceStatement": {
                                            "ARN": "arn"
                                        }
                                    }
                                ]
                            }
                        },
                        "VisibilityConfig": {
                            "CloudWatchMetricsEnabled": true,
                            "MetricName": "name",
                            "SampledRequestsEnabled": true
                        }
                    },
                    {
                        "Action": {
                            "Allow": {}
                        },
                        "Name": "Name1",
                        "Priority": 3,
                        "Statement": {
                            "ByteMatchStatement": {
                                "FieldToMatch": {
                                    "UriPath": {}
                                },
                                "PositionalConstraint": "CONTAINS",
                                "SearchString": "sdf",
                                "TextTransformations": [
                                    {
                                        "Priority": 0,
                                        "Type": "NONE"
                                    }
                                ]
                            }
                        },
                        "VisibilityConfig": {
                            "CloudWatchMetricsEnabled": true,
                            "MetricName": "Name1",
                            "SampledRequestsEnabled": true
                        }
                    },
                    {
                        "Action": {
                            "Allow": {}
                        },
                        "Name": "Name11",
                        "Priority": 4,
                        "Statement": {
                            "RegexPatternSetReferenceStatement": {
                                "ARN": "arn",
                                "FieldToMatch": {
                                    "UriPath": {}
                                },
                                "TextTransformations": [
                                    {
                                        "Priority": 0,
                                        "Type": "NONE"
                                    }
                                ]
                            }
                        },
                        "VisibilityConfig": {
                            "CloudWatchMetricsEnabled": true,
                            "MetricName": "name",
                            "SampledRequestsEnabled": true
                        }
                    }
                ],
                "VisibilityConfig": {
                    "CloudWatchMetricsEnabled": true,
                    "MetricName": "name",
                    "SampledRequestsEnabled": true
                }
            }
        }
    }
}

Human Readable Output

Rule group

Id Name Description
Id name  

aws-waf-rule-group-delete


Delete a specific rule group.

Base Command

aws-waf-rule-group-delete

Input

Argument Name Description Required
name The rule group name. Required
scope The rule group scope. Possible values are: Global, Regional. Default is Regional. Optional
id The rule group ID. Required
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

There is no context output for this command.

aws-waf-rule-group-create


Create a new rule group.

Base Command

aws-waf-rule-group-create

Input

Argument Name Description Required
name The rule group name. Required
scope The rule group scope. Possible values are: Global, Regional. Default is Regional. Optional
capacity The rule group capacity. Required
description The rule group description. Optional
cloud_watch_metrics_enabled Whether the associated resource sends metrics to Amazon CloudWatch. Possible values are: true, false. Default is true. Optional
metric_name The name of the Amazon CloudWatch metric dimension. The name can contain only the alphanumeric characters, hyphen, and underscore. The name can be from one to 128 characters long. It can’t contain whitespace or metric names that are reserved for AWS WAF. The default will be the same as the group name provided in the name argument. Optional
sampled_requests_enabled Whether to store a sampling of the web requests that match the rules. Possible values are: true, false. Default is true. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
tag_key A comma-separated list of the keys of the tags to associate with the rule group. Optional
tag_value A comma-separated list of the values of the tags to associate with the rule group. Optional

Context Output

Path Type Description
AWS.Waf.RuleGroup.Id String The rule group ID.
AWS.Waf.RuleGroup.Name String The rule group name.
AWS.Waf.RuleGroup.Description String The rule group description.
AWS.Waf.RuleGroup.LockToken String The rule group lock token.
AWS.Waf.RuleGroup.ARN String The rule group Amazon Resource Name.

Command example

!aws-waf-rule-group-create capacity=1500 name=name

Context Example

{
    "AWS": {
        "Waf": {
            "RuleGroup": {
                "ARN": "arn",
                "Description": "",
                "Id": "id",
                "LockToken": "lockToken",
                "Name": "name"
            }
        }
    }
}

Human Readable Output

AWS Waf rule group with id id was created successfully

aws-waf-ip-rule-create


Create an IP rule.

Base Command

aws-waf-ip-rule-create

Input

Argument Name Description Required
group_id The rule group ID to associate the rule to. Required
group_name The rule group name to associate the rule to. Required
rule_name The rule name. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
priority The rule priority. Required
action The rule action. Possible values are: Allow, Block, Count, Captcha, Challenge. Required
ip_set_arn A comma-separated list of the IP set ARN. You can get those values by running the aws-waf-ip-set-list command. Required
condition_operator The rule condition operator. If more than one value to the ip_set_arn argument is provided, a value must be provided. Possible values are: And, Or, Not. Optional

Context Output

There is no context output for this command.

aws-waf-country-rule-create


Create a country rule.

Base Command

aws-waf-country-rule-create

Input

Argument Name Description Required
group_id The rule group ID to associate the rule to. Required
group_name The rule group name to associate the rule to. Required
rule_name The rule name. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
priority The rule priority. Required
action The rule action. Possible values are: Allow, Block, Count, Captcha, Challenge. Required
country_codes A comma-separated list of two-character country codes. Required

Context Output

There is no context output for this command.

aws-waf-string-match-rule-create


Create a string match rule.

Base Command

aws-waf-string-match-rule-create

Input

Argument Name Description Required
group_id The rule group ID to associate the rule to. Required
group_name The rule group name to associate the rule to. Required
rule_name The rule name. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
priority The rule priority. Required
action The rule action. Possible values are: Allow, Block, Count, Captcha, Challenge. Required
match_type The string match type. Possible values are: Exactly Matches String, Starts With String, Ends With String, Contains String, Contains Words, Matches Regex Pattern Set. Required
string_to_match The string to match. If the match_type is Contains Words, a value must be provided. Optional
regex_set_arn The regex set ARN. You can get those values by running the aws-waf-regex-set-list command. If the match_type is Matches Regex Pattern Set, a value must be provided. Optional
web_request_component The web component to inspect. Possible values are: Headers, Cookies, Query Parameters, Uri Path, Query String, Body, HTTP Method. Required
oversize_handling AWS WAF applies oversize handling to web request contents that are larger than AWS WAF can inspect. If the web_request_component is Headers, Cookies or Body, a value must be provided. Possible values are: CONTINUE, MATCH, NO_MATCH. Optional
text_transformation The text transformation to perform. Possible values are: NONE, COMPRESS_WHITE_SPACE, HTML_ENTITY_DECODE, LOWERCASE, CMD_LINE, URL_DECODE, BASE64_DECODE, HEX_DECODE, MD5, REPLACE_COMMENTS, ESCAPE_SEQ_DECODE, SQL_HEX_DECODE, CSS_DECODE, JS_DECODE, NORMALIZE_PATH, NORMALIZE_PATH_WIN, REMOVE_NULLS, REPLACE_NULLS, BASE64_DECODE_EXT, URL_DECODE_UNI, UTF8_TO_UNICODE. Default is NONE. Optional

Context Output

There is no context output for this command.

aws-waf-rule-delete


Delete a specific rule from a rule group.

Base Command

aws-waf-rule-delete

Input

Argument Name Description Required
group_id The rule group ID to delete the rule from. Required
group_name The rule group name to delete the rule from. Required
rule_name The rule name. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional

Context Output

There is no context output for this command.

aws-waf-ip-statement-add


Adds an IP statement to an existing rule.

Base Command

aws-waf-ip-statement-add

Input

Argument Name Description Required
group_id The rule group ID to associate the statement to. Required
group_name The rule group name to associate the statement to. Required
rule_name The rule name to associate the statement to. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
ip_set_arn The IP set ARN. You can get this value by running the aws-waf-ip-set-list command. Required
condition_operator The rule condition operator. If the rule contains only one statement, a value must be provided. If the rule already contains multiple statements, this argument would be ignored. Possible values are: And, Or. Optional

Context Output

There is no context output for this command.

aws-waf-country-statement-add


Adds a country statement to an existing rule.

Base Command

aws-waf-country-statement-add

Input

Argument Name Description Required
group_id The rule group ID to associate the statement to. Required
group_name The rule group name to associate the statement to. Required
rule_name The rule name to associate the statement to. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
country_codes A comma-separated list of two-character country codes. Required
condition_operator The rule condition operator. If the rule contains only one statement, a value must be provided. If the rule already contains multiple statements, this argument would be ignored. Possible values are: And, Or. Optional

Context Output

There is no context output for this command.

aws-waf-string-match-statement-add


Adds a string match statement to an existing rule.

Base Command

aws-waf-string-match-statement-add

Input

Argument Name Description Required
group_id The rule group ID to associate the statement to. Required
group_name The rule group name to associate the statement to. Required
rule_name The rule name to associate the statement to. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
match_type The string match type. Possible values are: Exactly Matches String, Starts With String, Ends With String, Contains String, Contains Words, Matches Regex Pattern Set. Required
string_to_match The string to match. If the match_type is Contains Words, a value must be provided. Optional
regex_set_arn The regex set ARN. You can get those values by running the aws-waf-regex-set-list command. If the match_type is Matches Regex Pattern Set, a value must be provided. Optional
web_request_component The web component to inspect. Possible values are: Headers, Cookies, Query Parameters, Uri Path, Query String, Body, HTTP Method. Required
oversize_handling AWS WAF applies oversize handling to web request contents that are larger than AWS WAF can inspect. If the web_request_component is Headers, Cookies or Body, a value must be provided. Possible values are: CONTINUE, MATCH, NO_MATCH. Optional
text_transformation The text transformation to perform. Possible values are: NONE, COMPRESS_WHITE_SPACE, HTML_ENTITY_DECODE, LOWERCASE, CMD_LINE, URL_DECODE, BASE64_DECODE, HEX_DECODE, MD5, REPLACE_COMMENTS, ESCAPE_SEQ_DECODE, SQL_HEX_DECODE, CSS_DECODE, JS_DECODE, NORMALIZE_PATH, NORMALIZE_PATH_WIN, REMOVE_NULLS, REPLACE_NULLS, BASE64_DECODE_EXT, URL_DECODE_UNI, UTF8_TO_UNICODE. Default is NONE. Optional
condition_operator The rule condition operator. If the rule contains only one statement, a value must be provided. If the rule already contains multiple statements, this argument would be ignored. Possible values are: And, Or. Optional

Context Output

There is no context output for this command.

aws-waf-statement-json-add


Adds a generic statement to an existing rule.

Base Command

aws-waf-statement-json-add

Input

Argument Name Description Required
group_id The rule group ID to associate the statement to. Required
group_name The rule group name to associate the statement to. Required
rule_name The rule name to associate the statement to. Required
scope The rule scope. Possible values are: Global, Regional. Default is Regional. Optional
region The AWS Region. If not specified, the default region will be used. Possible values are: us-east-1, us-east-2, us-west-1, us-west-2, ca-central-1, eu-west-1, eu-central-1, eu-west-2, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, sa-east-1, eu-north-1, eu-west-3, us-gov-east-1, us-gov-west-1. Optional
statement_json A generic JSON statement to add to the rule. You can get the templates by running the aws-waf-statement-json-template-get command. Required
condition_operator The rule condition operator. If the rule contains only one statement, a value must be provided. If the rule already contains multiple statements, this argument would be ignored. Possible values are: And, Or. Optional

Context Output

There is no context output for this command.

aws-waf-statement-json-template-get


Gets the statement template.

Base Command

aws-waf-statement-json-template-get

Input

Argument Name Description Required
statement_type The statement type. Possible values are: Ip Set, Country, String Match, Regex Pattern. Required
web_request_component The web component to inspect. Possible values are: Headers, Cookies, Query Parameters, Uri Path, Query String, Body, HTTP Method. Optional

Context Output

There is no context output for this command.

Configuration parameters

  • roleArn — Role Arn
  • roleSessionName — Role Session Name
  • defaultRegion — AWS Default Region (required)
  • sessionDuration — Role Session Duration
  • access_key
  • secret_key
  • timeout — Timeout
  • retries — Retries
  • sts_regional_endpoint — AWS STS Regional Endpoints
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (23)

  • aws-waf-country-rule-create

    Create a country rule.

  • aws-waf-country-statement-add

    Adds a country statement to an existing rule.

  • aws-waf-ip-rule-create

    Create an IP rule.

  • aws-waf-ip-set-create

    Create a new IP set.

  • aws-waf-ip-set-delete

    Delete a specific IP set.

  • aws-waf-ip-set-get

    Get a specific IP set.

  • aws-waf-ip-set-list

    Lists IP sets.

  • aws-waf-ip-set-update

    Update an IP set.

  • aws-waf-ip-statement-add

    Adds an IP statement to an existing rule.

  • aws-waf-regex-set-create

    Create a new regex set.

  • aws-waf-regex-set-delete

    Delete a specific regex set.

  • aws-waf-regex-set-get

    Get a specific regex set.

  • aws-waf-regex-set-list

    Lists regex sets.

  • aws-waf-regex-set-update

    Update a regex set.

  • aws-waf-rule-delete

    Delete a specific rule from a rule group.

  • aws-waf-rule-group-create

    Create a new rule group.

  • aws-waf-rule-group-delete

    Delete a specific rule group.

  • aws-waf-rule-group-get

    Get a specific rule group.

  • aws-waf-rule-group-list

    Lists rule groups.

  • aws-waf-statement-json-add

    Adds a generic statement to an existing rule.

  • aws-waf-statement-json-template-get

    Gets the statement template.

  • aws-waf-string-match-rule-create

    Create a string match rule.

  • aws-waf-string-match-statement-add

    Adds a string match statement to an existing rule.

import json

import pytest
from AWSWAF import BYTE_MATCH_STATEMENT, OPERATOR_TO_STATEMENT_OPERATOR, REGEX_MATCH_STATEMENT
from CommonServerPython import *

IP_ARN_LIST = ["ip_arn", "ip_arn1"]
AND_CONDITION_OPERATOR = "And"
OR_CONDITION_OPERATOR = "Or"


class MockedBoto3Client:
    """Mocked AWSClient session for easier expectation settings."""

    def create_ip_set(self, **kwargs):
        pass

    def get_ip_set(self, **kwargs):
        pass

    def update_ip_set(self, **kwargs):
        pass

    def list_ip_sets(self, **kwargs):
        pass

    def delete_ip_set(self, **kwargs):
        pass

    def create_regex_pattern_set(self, **kwargs):
        pass

    def get_regex_pattern_set(self, **kwargs):
        pass

    def update_regex_pattern_set(self, **kwargs):
        pass

    def list_regex_pattern_sets(self, **kwargs):
        pass

    def delete_regex_pattern_set(self, **kwargs):
        pass

    def create_rule_group(self, **kwargs):
        pass

    def get_rule_group(self, **kwargs):
        pass

    def list_rule_groups(self, **kwargs):
        pass

    def delete_rule_group(self, **kwargs):
        pass


def util_load_json(path):
    with open(f"test_data/{path}.json", encoding="utf-8") as f:
        return json.loads(f.read())


def test_get_tags_dict_from_args():
    """
    Given:
        tags keys and tags values lists of same length

    When:
        Creating tags for create commands

    Then:
        assert tags list has same length as the tags and values lists
    """
    from AWSWAF import get_tags_dict_from_args

    tag_keys = ["tag1", "tag2"]
    tag_values = ["value1", "value2"]
    result = get_tags_dict_from_args(tag_keys=tag_keys, tag_values=tag_values)
    assert len(result) == 2


def test_get_tags_dict_from_args_raise_exception():
    """
    Given:
        tags keys and tags values lists  of different lengths

    When:
        Creating tags for create commands

    Then:
        assert exception wis raised
    """
    from AWSWAF import get_tags_dict_from_args

    tag_keys = ["tag1"]
    tag_values = ["value1", "value2"]
    with pytest.raises(DemistoException):
        get_tags_dict_from_args(tag_keys=tag_keys, tag_values=tag_values)


def test_build_regex_pattern_object():
    """
    Given:
        Regex patterns list

    When:
        Creating regex pattern object

    Then:
        assert object was being created correctly
    """
    from AWSWAF import build_regex_pattern_object

    regex_patterns = ["pattern1", "pattern2"]
    result = build_regex_pattern_object(regex_patterns=regex_patterns)
    assert len(result) == 2


@pytest.mark.parametrize(
    "args, expected_result",
    [
        ({"ip_set_arn": IP_ARN_LIST[:1]}, "IPSetReferenceStatement"),
        (
            {"ip_set_arn": IP_ARN_LIST, "condition_operator": AND_CONDITION_OPERATOR},
            OPERATOR_TO_STATEMENT_OPERATOR[AND_CONDITION_OPERATOR],
        ),
    ],
)
def test_build_ip_rule_object(args, expected_result):
    """
    Given:
        IP sets arns

    When:
        Creating a new rule object

    Then:
        assert object['Statement'] contains one statement object
        assert object['Statement'] contains statement operator
    """
    from AWSWAF import build_ip_rule_object

    ip_rule = build_ip_rule_object(args=args)
    assert expected_result in ip_rule["Statement"]


@pytest.mark.parametrize(
    "rule_file, statement_condition, statements",
    [
        (
            "rule_one_statement",
            OPERATOR_TO_STATEMENT_OPERATOR[AND_CONDITION_OPERATOR],
            [{"IPSetReferenceStatement": {"ARN": "ip_arn"}}],
        ),
        (
            "rule_two_statements",
            OPERATOR_TO_STATEMENT_OPERATOR[OR_CONDITION_OPERATOR],
            [{"IPSetReferenceStatement": {"ARN": "ip_arn"}}, {"IPSetReferenceStatement": {"ARN": "ip_arn1"}}],
        ),
    ],
)
def test_update_rule_with_statement(rule_file, statement_condition, statements):
    """
    Given:
        Rule statements

    When:
        Updating an existing rule with a statement

    Then:
        assert object['Statement'] contains the given condition operator
        assert object['Statement'] contains the existing condition operator
    """
    from AWSWAF import update_rule_with_statement

    rule = util_load_json(rule_file)
    update_rule_with_statement(rule=rule, statements=statements, condition_operator=AND_CONDITION_OPERATOR)
    assert statement_condition in rule["Statement"]


def test_create_rules_list_with_new_rule_statement(mocker):
    """
    Given:
        Rule name to update

    When:
        Updating an existing rule with a statement

    Then:
        assert updating happens to the correct rule
    """
    from AWSWAF import create_rules_list_with_new_rule_statement

    rules = util_load_json("rule_group").get("RuleGroup").get("Rules")
    args = {"rule_name": "test_1"}
    res = mocker.patch("AWSWAF.update_rule_with_statement")
    create_rules_list_with_new_rule_statement(args=args, statements=[{}], rules=rules)
    assert res.call_count == 1


@pytest.mark.parametrize(
    "match_type, regex_set_arn, string_to_match, expected_exception",
    [
        ("Exactly Matches String", "regex_arn", None, "string_to_match must be provided"),
        ("Matches Regex Pattern Set", None, "str_to_match", "regex_set_arn must be provided"),
    ],
)
def test_build_string_match_statement_raise_exception(match_type, regex_set_arn, string_to_match, expected_exception):
    """
    Given:
        String match statement related parameters

    When:
        Creating a string match statement

    Then:
        assert exception is raised when wrong parameters are provided
    """
    from AWSWAF import build_string_match_statement

    with pytest.raises(DemistoException) as e:
        build_string_match_statement(match_type=match_type)
        assert expected_exception in str(e)


@pytest.mark.parametrize(
    "match_type, string_to_match, regex_set_arn, oversize_handling, "
    "text_transformation, web_request_component, expected_result, match_statement",
    [
        ("Exactly Matches String", "str_to_match", None, "CONTINUE", "NONE", "Body", "SearchString", BYTE_MATCH_STATEMENT),
        ("Matches Regex Pattern Set", None, "regex_arn", None, None, "UriPath", "ARN", REGEX_MATCH_STATEMENT),
    ],
)
def test_build_string_match_statement(
    match_type,
    string_to_match,
    regex_set_arn,
    oversize_handling,
    text_transformation,
    web_request_component,
    expected_result,
    match_statement,
):
    """
    Given:
        String match statement related parameters

    When:
        Creating a string match statement

    Then:
        assert the created object matches the match type
    """
    from AWSWAF import build_string_match_statement

    statement = build_string_match_statement(
        match_type, string_to_match, regex_set_arn, oversize_handling, text_transformation, web_request_component
    )
    assert expected_result in statement[match_statement]


@pytest.mark.parametrize(
    "web_request_component, oversize_handling, expected_result",
    [
        ("Cookies", "CONTINUE", {"MatchPattern": {"All": {}}, "MatchScope": "ALL", "OversizeHandling": "CONTINUE"}),
        ("UriPath", None, {}),
        ("Body", "CONTINUE", {"OversizeHandling": "CONTINUE"}),
    ],
)
def test_build_web_component_match_object(web_request_component, oversize_handling, expected_result):
    """
    Given:
        web_request_component, oversize_handling

    When:
        Creating a web component object

    Then:
        assert that oversize_handling exists for the relevant web components
        assert that match pattern exists for the relevant web components
    """
    from AWSWAF import build_web_component_match_object

    web_request_component_object = build_web_component_match_object(web_request_component, oversize_handling)
    assert web_request_component_object == expected_result


def test_delete_rule():
    """
    Given:
        Rules list and rule to delete

    When:
        Deleting a rule

    Then:
        assert rule has been deleted
    """
    from AWSWAF import delete_rule

    original_rules = util_load_json("rule_group").get("RuleGroup").get("Rules")
    deleted_rules = delete_rule(rule_name="test_1", rules=original_rules)
    assert len(original_rules) == len(deleted_rules) + 1


def test_append_new_rule():
    """
    Given:
        Rules list and rule to add

    When:
        Creating a rule

    Then:
        assert rule has been created and appended
    """
    from AWSWAF import append_new_rule

    original_rules = util_load_json("rule_group").get("RuleGroup").get("Rules")
    rule = util_load_json("rule_one_statement")
    updated_rules = append_new_rule(rule=rule, rules=original_rules)
    assert len(original_rules) == len(updated_rules) - 1


"""COMMANDS TESTS"""


def test_create_ip_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Creating ip set

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import create_ip_set_command

    client = MockedBoto3Client()
    create_ip_set_args = {"name": "name", "scope": "Regional", "ip_version": "IPV4", "addresses": []}
    create_ip_set_mock = mocker.patch.object(client, "create_ip_set")
    create_ip_set_command(client=client, args=create_ip_set_args)
    create_ip_set_mock.assert_called_with(Name="name", Scope="REGIONAL", IPAddressVersion="IPV4", Addresses=[])


def test_get_ip_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Getting ip set

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import get_ip_set_command

    client = MockedBoto3Client()
    get_ip_set_args = {"name": "name", "scope": "Regional", "id": "id"}
    get_ip_set_mock = mocker.patch.object(client, "get_ip_set")
    get_ip_set_command(client=client, args=get_ip_set_args)
    get_ip_set_mock.assert_called_with(Name="name", Scope="REGIONAL", Id="id")


@pytest.mark.parametrize("is_overwrite, updated_addresses", [(True, ["1.1.1.2/32"]), (False, ["1.1.1.2/32", "1.1.2.2/32"])])
def test_update_ip_set_command(mocker, is_overwrite, updated_addresses):
    """
    Given:
        Command arguments

    When:
        Updating ip set

    Then:
        assert api request was called with the required parameters
        assert the addresses list is updated according to overwrite argument
    """
    from AWSWAF import update_ip_set_command

    client = MockedBoto3Client()
    update_ip_set_args = {
        "name": "name",
        "scope": "Regional",
        "ip_version": "IPV4",
        "addresses": "1.1.1.2/32",
        "is_overwrite": is_overwrite,
        "id": "id",
    }
    get_ip_set_response = util_load_json("get_ip_set_response")
    mocker.patch.object(client, "get_ip_set", return_value=get_ip_set_response)
    update_ip_set_mock = mocker.patch.object(client, "update_ip_set")
    update_ip_set_command(client=client, args=update_ip_set_args)
    update_ip_set_mock.assert_called_with(
        Name="name", Id="id", Scope="REGIONAL", LockToken="lockToken", Addresses=updated_addresses
    )


def test_list_ip_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Listing ip sets

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import list_ip_set_command

    client = MockedBoto3Client()
    list_ip_set_args = {"scope": "Regional"}
    list_ip_sets_mock = mocker.patch.object(client, "list_ip_sets")
    list_ip_set_command(client=client, args=list_ip_set_args)
    list_ip_sets_mock.assert_called_with(Scope="REGIONAL", Limit=50)


def test_delete_ip_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Deleting ip set

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import delete_ip_set_command

    client = MockedBoto3Client()
    delete_ip_set_args = {"name": "name", "scope": "Regional", "id": "id"}
    get_ip_set_response = util_load_json("get_ip_set_response")
    mocker.patch.object(client, "get_ip_set", return_value=get_ip_set_response)
    delete_ip_set_mock = mocker.patch.object(client, "delete_ip_set")
    delete_ip_set_command(client=client, args=delete_ip_set_args)
    delete_ip_set_mock.assert_called_with(Name="name", Id="id", Scope="REGIONAL", LockToken="lockToken")


def test_create_regex_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Creating regex patterns set

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import create_regex_set_command

    client = MockedBoto3Client()
    create_regex_set_args = {"name": "name", "scope": "Regional", "regex_pattern": "regex_pattern"}
    create_regex_set_mock = mocker.patch.object(client, "create_regex_pattern_set")
    create_regex_set_command(client=client, args=create_regex_set_args)
    create_regex_set_mock.assert_called_with(
        Name="name", Scope="REGIONAL", RegularExpressionList=[{"RegexString": "regex_pattern"}]
    )


def test_get_regex_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Getting regex patterns set

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import get_regex_set_command

    client = MockedBoto3Client()
    get_regex_set_args = {"name": "name", "scope": "Regional", "id": "id"}
    get_regex_set_mock = mocker.patch.object(client, "get_regex_pattern_set")
    get_regex_set_command(client=client, args=get_regex_set_args)
    get_regex_set_mock.assert_called_with(Name="name", Scope="REGIONAL", Id="id")


@pytest.mark.parametrize(
    "is_overwrite, updated_regex_list",
    [(True, [{"RegexString": "regex_pattern1"}]), (False, [{"RegexString": "regex_pattern1"}, {"RegexString": "regex_pattern"}])],
)
def test_update_regex_set_command(mocker, is_overwrite, updated_regex_list):
    """
    Given:
        Command arguments

    When:
        Updating regex patterns set

    Then:
        assert api request was called with the required parameters
        assert regex patterns list was updated according to the overwrite parameter
    """
    from AWSWAF import update_regex_set_command

    client = MockedBoto3Client()
    update_regex_set_args = {
        "name": "name",
        "scope": "Regional",
        "regex_pattern": "regex_pattern1",
        "is_overwrite": is_overwrite,
        "id": "id",
    }
    get_regex_set_response = util_load_json("get_regex_set_response")
    mocker.patch.object(client, "get_regex_pattern_set", return_value=get_regex_set_response)
    update_regex_set_mock = mocker.patch.object(client, "update_regex_pattern_set")
    update_regex_set_command(client=client, args=update_regex_set_args)
    update_regex_set_mock.assert_called_with(
        Name="name", Id="id", Scope="REGIONAL", LockToken="lockToken", RegularExpressionList=updated_regex_list
    )


def test_list_regex_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Listing regex patterns set

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import list_regex_set_command

    client = MockedBoto3Client()
    list_regex_set_args = {"scope": "Regional"}
    list_regex_sets_mock = mocker.patch.object(client, "list_regex_pattern_sets")
    list_regex_set_command(client=client, args=list_regex_set_args)
    list_regex_sets_mock.assert_called_with(Scope="REGIONAL", Limit=50)


def test_delete_regex_set_command(mocker):
    """
    Given:
        Command arguments

    When:
        Deleting regex patterns set

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import delete_regex_set_command

    client = MockedBoto3Client()
    delete_regex_set_args = {"name": "name", "scope": "Regional", "id": "id"}
    get_regex_set_response = util_load_json("get_regex_set_response")
    mocker.patch.object(client, "get_regex_pattern_set", return_value=get_regex_set_response)
    delete_regex_set_mock = mocker.patch.object(client, "delete_regex_pattern_set")
    delete_regex_set_command(client=client, args=delete_regex_set_args)
    delete_regex_set_mock.assert_called_with(Name="name", Id="id", Scope="REGIONAL", LockToken="lockToken")


def test_list_rule_group_command(mocker):
    """
    Given:
        Command arguments

    When:
        Listing rule group

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import list_rule_group_command

    client = MockedBoto3Client()
    list_rule_group_args = {"scope": "Regional"}
    list_rule_group_mock = mocker.patch.object(client, "list_rule_groups")
    list_rule_group_command(client=client, args=list_rule_group_args)
    list_rule_group_mock.assert_called_with(Scope="REGIONAL", Limit=50)


def test_get_rule_group_command(mocker):
    """
    Given:
        Command arguments

    When:
        Getting rule group

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import get_rule_group_command

    client = MockedBoto3Client()
    get_rule_group_args = {"name": "name", "scope": "Regional", "id": "id"}
    get_rule_group_mock = mocker.patch.object(client, "get_rule_group")
    get_rule_group_command(client=client, args=get_rule_group_args)
    get_rule_group_mock.assert_called_with(Name="name", Scope="REGIONAL", Id="id")


def test_create_rule_group_command(mocker):
    """
    Given:
        Command arguments

    When:
        Creating rule group

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import create_rule_group_command

    client = MockedBoto3Client()
    create_rule_group_args = {
        "name": "name",
        "scope": "Regional",
        "capacity": 100,
        "cloud_watch_metrics_enabled": True,
        "sampled_requests_enabled": True,
    }
    expected_visibility_config = {"CloudWatchMetricsEnabled": True, "MetricName": "name", "SampledRequestsEnabled": True}
    create_rule_group_mock = mocker.patch.object(client, "create_rule_group")
    create_rule_group_command(client=client, args=create_rule_group_args)
    create_rule_group_mock.assert_called_with(
        Name="name", Scope="REGIONAL", Capacity=100, VisibilityConfig=expected_visibility_config
    )


def test_delete_rule_group_command(mocker):
    """
    Given:
        Command arguments

    When:
        Deleting rule group

    Then:
        assert api request was called with the required parameters
    """
    from AWSWAF import delete_rule_group_command

    client = MockedBoto3Client()
    delete_rule_group_args = {"name": "name", "scope": "Regional", "id": "id"}
    get_rule_group_response = util_load_json("rule_group")
    mocker.patch.object(client, "get_rule_group", return_value=get_rule_group_response)
    delete_rule_group_mock = mocker.patch.object(client, "delete_rule_group")
    delete_rule_group_command(client=client, args=delete_rule_group_args)
    delete_rule_group_mock.assert_called_with(Name="name", Id="id", Scope="REGIONAL", LockToken="lockToken")