Skip to content

create_web_acl

create_web_acl(
    name: ResourceName,
    metric_name: MetricName,
    default_action: WafAction,
    change_token: ChangeToken,
    *,
    config_overrides: Optional[WAFRegionalClientConfig] = None,
    tags: Optional[TagList] = None,
) -> CreateWebACLResponse

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.

Creates a WebACL, which contains the Rules that identify the CloudFront web requests that you want to allow, block, or count. AWS WAF evaluates Rules in order based on the value of Priority for each Rule.

You also specify a default action, either ALLOW or BLOCK. If a web request doesn't match any of the Rules in a WebACL, AWS WAF responds to the request with the default action.

To create and configure a WebACL, perform the following steps:

  1. Create and update the ByteMatchSet objects and other predicates that you want to include in Rules. For more information, see CreateByteMatchSet, UpdateByteMatchSet, CreateIPSet, UpdateIPSet, CreateSqlInjectionMatchSet, and UpdateSqlInjectionMatchSet.

  2. Create and update the Rules that you want to include in the WebACL. For more information, see CreateRule and UpdateRule.

  3. Use GetChangeToken to get the change token that you provide in the ChangeToken parameter of a CreateWebACL request.

  4. Submit a CreateWebACL request.

  5. Use GetChangeToken to get the change token that you provide in the ChangeToken parameter of an UpdateWebACL request.

  6. Submit an UpdateWebACL request to specify the Rules that you want to include in the WebACL, to specify the default action, and to associate the WebACL with a CloudFront distribution.

For more information about how to use the AWS WAF API, see the AWS WAF Developer Guide.

Parameters:

  • name (ResourceName) –

    A friendly name or description of the WebACL. You can't change Name after you create the WebACL.

  • metric_name (MetricName) –

    A friendly name or description for the metrics for this WebACL.The name can contain only alphanumeric characters (A-Z, a-z, 0-9), with maximum length 128 and minimum length one. It can't contain whitespace or metric names reserved for AWS WAF, including "All" and "Default_Action." You can't change MetricName after you create the WebACL.

  • default_action (WafAction) –

    The action that you want AWS WAF to take when a request doesn't match the criteria specified in any of the Rule objects that are associated with the WebACL.

  • change_token (ChangeToken) –

    The value returned by the most recent call to GetChangeToken.

  • tags (Optional[TagList], default: None ) –

Raises:

  • WAFBadRequestException –

  • WAFDisallowedNameException –

    The name specified is invalid.

  • WAFInternalErrorException –

    The operation failed because of a system problem, even though the request was valid. Retry your request.

  • WAFInvalidAccountException –

    The operation failed because you tried to create, update, or delete an object by using an invalid account identifier.

  • WAFInvalidParameterException –

    The operation failed because AWS WAF didn't recognize a parameter in the request. For example:

    • You specified an invalid parameter name.

    • You specified an invalid value.

    • You tried to update an object (ByteMatchSet, IPSet, Rule, or WebACL) using an action other than INSERT or DELETE.

    • You tried to create a WebACL with a DefaultAction Type other than ALLOW, BLOCK, or COUNT.

    • You tried to create a RateBasedRule with a RateKey value other than IP.

    • You tried to update a WebACL with a WafAction Type other than ALLOW, BLOCK, or COUNT.

    • You tried to update a ByteMatchSet with a FieldToMatch Type other than HEADER, METHOD, QUERY_STRING, URI, or BODY.

    • You tried to update a ByteMatchSet with a Field of HEADER but no value for Data.

    • Your request references an ARN that is malformed, or corresponds to a resource with which a web ACL cannot be associated.

  • WAFLimitsExceededException –

    The operation exceeds a resource limit, for example, the maximum number of WebACL objects that you can create for an AWS account. For more information, see Limits in the AWS WAF Developer Guide.

  • WAFStaleDataException –

    The operation failed because you tried to create, update, or delete an object by using a change token that has already been used.

  • WAFTagOperationException –

  • WAFTagOperationInternalErrorException –

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To create a web ACL The following example creates a web ACL named CreateExample.

>>> client.create_web_acl(name='CreateExample', metric_name='CreateExample', default_action={'Type': 'ALLOW'}, change_token='abcd12f2-46da-4fdb-b8d5-fbd4c466928f')
Source code in docs_src/capo_waf_regional/_services/waf_regional.py
def create_web_acl(
    self,
    name: "capo_waf_regional.types.resource_name.ResourceName",
    metric_name: "capo_waf_regional.types.metric_name.MetricName",
    default_action: "capo_waf_regional.types.waf_action.WafAction",
    change_token: "capo_waf_regional.types.change_token.ChangeToken",
    *,
    config_overrides: Optional[WAFRegionalClientConfig] = None,
    tags: Optional["capo_waf_regional.types.tag_list.TagList"] = None,
) -> "capo_waf_regional.types.create_web_acl_response.CreateWebACLResponse":
    """<note> <p>This is <b>AWS WAF Classic</b> documentation. For more information, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html">AWS WAF Classic</a> in the developer guide.</p> <p> <b>For the latest version of AWS WAF</b>, use the AWS WAFV2 API and see the <a href="https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html">AWS WAF Developer Guide</a>. With the latest version, AWS WAF has a single set of endpoints for regional and global use. </p> </note> <p>Creates a <code>WebACL</code>, which contains the <code>Rules</code> that identify the CloudFront web requests that you want to allow, block, or count. AWS WAF evaluates <code>Rules</code> in order based on the value of <code>Priority</code> for each <code>Rule</code>.</p> <p>You also specify a default action, either <code>ALLOW</code> or <code>BLOCK</code>. If a web request doesn't match any of the <code>Rules</code> in a <code>WebACL</code>, AWS WAF responds to the request with the default action. </p> <p>To create and configure a <code>WebACL</code>, perform the following steps:</p> <ol> <li> <p>Create and update the <code>ByteMatchSet</code> objects and other predicates that you want to include in <code>Rules</code>. For more information, see <a>CreateByteMatchSet</a>, <a>UpdateByteMatchSet</a>, <a>CreateIPSet</a>, <a>UpdateIPSet</a>, <a>CreateSqlInjectionMatchSet</a>, and <a>UpdateSqlInjectionMatchSet</a>.</p> </li> <li> <p>Create and update the <code>Rules</code> that you want to include in the <code>WebACL</code>. For more information, see <a>CreateRule</a> and <a>UpdateRule</a>.</p> </li> <li> <p>Use <a>GetChangeToken</a> to get the change token that you provide in the <code>ChangeToken</code> parameter of a <code>CreateWebACL</code> request.</p> </li> <li> <p>Submit a <code>CreateWebACL</code> request.</p> </li> <li> <p>Use <code>GetChangeToken</code> to get the change token that you provide in the <code>ChangeToken</code> parameter of an <a>UpdateWebACL</a> request.</p> </li> <li> <p>Submit an <a>UpdateWebACL</a> request to specify the <code>Rules</code> that you want to include in the <code>WebACL</code>, to specify the default action, and to associate the <code>WebACL</code> with a CloudFront distribution.</p> </li> </ol> <p>For more information about how to use the AWS WAF API, see the <a href="https://docs.aws.amazon.com/waf/latest/developerguide/">AWS WAF Developer Guide</a>.</p>

    Args:
        name: <p>A friendly name or description of the <a>WebACL</a>. You can't change <code>Name</code> after you create the <code>WebACL</code>.</p>
        metric_name: <p>A friendly name or description for the metrics for this <code>WebACL</code>.The name can contain only alphanumeric characters (A-Z, a-z, 0-9), with maximum length 128 and minimum length one. It can't contain whitespace or metric names reserved for AWS WAF, including "All" and "Default_Action." You can't change <code>MetricName</code> after you create the <code>WebACL</code>.</p>
        default_action: <p>The action that you want AWS WAF to take when a request doesn't match the criteria specified in any of the <code>Rule</code> objects that are associated with the <code>WebACL</code>.</p>
        change_token: <p>The value returned by the most recent call to <a>GetChangeToken</a>.</p>
        tags: <p></p>

    Raises:
        capo_waf_regional.errors.waf_bad_request_exception.WAFBadRequestException: <p></p>
        capo_waf_regional.errors.waf_disallowed_name_exception.WAFDisallowedNameException: <p>The name specified is invalid.</p>
        capo_waf_regional.errors.waf_internal_error_exception.WAFInternalErrorException: <p>The operation failed because of a system problem, even though the request was valid. Retry your request.</p>
        capo_waf_regional.errors.waf_invalid_account_exception.WAFInvalidAccountException: <p>The operation failed because you tried to create, update, or delete an object by using an invalid account identifier.</p>
        capo_waf_regional.errors.waf_invalid_parameter_exception.WAFInvalidParameterException: <p>The operation failed because AWS WAF didn't recognize a parameter in the request. For example:</p> <ul> <li> <p>You specified an invalid parameter name.</p> </li> <li> <p>You specified an invalid value.</p> </li> <li> <p>You tried to update an object (<code>ByteMatchSet</code>, <code>IPSet</code>, <code>Rule</code>, or <code>WebACL</code>) using an action other than <code>INSERT</code> or <code>DELETE</code>.</p> </li> <li> <p>You tried to create a <code>WebACL</code> with a <code>DefaultAction</code> <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>, or <code>COUNT</code>.</p> </li> <li> <p>You tried to create a <code>RateBasedRule</code> with a <code>RateKey</code> value other than <code>IP</code>.</p> </li> <li> <p>You tried to update a <code>WebACL</code> with a <code>WafAction</code> <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>, or <code>COUNT</code>.</p> </li> <li> <p>You tried to update a <code>ByteMatchSet</code> with a <code>FieldToMatch</code> <code>Type</code> other than HEADER, METHOD, QUERY_STRING, URI, or BODY.</p> </li> <li> <p>You tried to update a <code>ByteMatchSet</code> with a <code>Field</code> of <code>HEADER</code> but no value for <code>Data</code>.</p> </li> <li> <p>Your request references an ARN that is malformed, or corresponds to a resource with which a web ACL cannot be associated.</p> </li> </ul>
        capo_waf_regional.errors.waf_limits_exceeded_exception.WAFLimitsExceededException: <p>The operation exceeds a resource limit, for example, the maximum number of <code>WebACL</code> objects that you can create for an AWS account. For more information, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/limits.html">Limits</a> in the <i>AWS WAF Developer Guide</i>.</p>
        capo_waf_regional.errors.waf_stale_data_exception.WAFStaleDataException: <p>The operation failed because you tried to create, update, or delete an object by using a change token that has already been used.</p>
        capo_waf_regional.errors.waf_tag_operation_exception.WAFTagOperationException: <p></p>
        capo_waf_regional.errors.waf_tag_operation_internal_error_exception.WAFTagOperationInternalErrorException: <p></p>
        capo_waf_regional.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create a web ACL
        The following example creates a web ACL named CreateExample.

        >>> client.create_web_acl(name='CreateExample', metric_name='CreateExample', default_action={'Type': 'ALLOW'}, change_token='abcd12f2-46da-4fdb-b8d5-fbd4c466928f')
    """

    def _handler(
        req: "OperationRequest[capo_waf_regional.types.create_web_acl_request.CreateWebACLRequest]",
    ) -> OperationResponse[
        "capo_waf_regional.types.create_web_acl_response.CreateWebACLResponse"
    ]:
        import capo_waf_regional._operations.awswaf_regional_20161128.create_web_acl

        output, http_response = (
            capo_waf_regional._operations.awswaf_regional_20161128.create_web_acl.create_web_acl(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateWebACL")
    )
    input_: capo_waf_regional.types.create_web_acl_request.CreateWebACLRequest = {
        "name": name,
        "metric_name": metric_name,
        "default_action": default_action,
        "change_token": change_token,
    }
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output