Skip to content

create_rule async

create_rule(
    rule_name: RuleName,
    firewall_type: RuleFirewallType,
    rule_type: RuleType,
    configuration: JsonDocument,
    *,
    config_overrides: Optional[AsyncNetworkSecurityManagerClientConfig] = None,
    client_token: Optional[IdempotencyToken] = None,
    rule_description: Optional[Description] = None,
    is_published: Optional[IsPublished] = None,
    tags: Optional[TagMap] = None,
) -> CreateRuleOutput

Creates a rule. A rule defines a network security configuration to enforce, such as an AWS WAF rule group or configuration data. Use isPublished to create the rule in published (ACTIVE) or draft (DRAFT) state.

Parameters:

  • client_token (Optional[IdempotencyToken], default: None ) –

    A unique, case-sensitive token that you provide to ensure that the operation completes no more than one time. If you retry a request with the same client token and the same parameters, the service returns the result of the original successful request.

  • rule_name (RuleName) –

    The name of the rule.

  • firewall_type (RuleFirewallType) –

    The firewall type associated with the resource.

  • rule_type (RuleType) –

    The type of the rule. CONFIGURATION rules contain firewall settings, and INSPECTION rules contain rule groups.

  • rule_description (Optional[Description], default: None ) –

    A description of the rule.

  • configuration (JsonDocument) –

    The firewall configuration for the rule, as a JSON document. The structure depends on the rule's firewall type and rule type. For an AWS WAF INSPECTION rule, provide an AWS WAF rule group. For an AWS WAF CONFIGURATION rule, provide a single web ACL setting, such as DefaultAction or VisibilityConfig; use wafConfigDataType to declare which setting the document contains. For the schema of each setting and complete examples, see Writing rule configurations in the AWS Network Security Manager Developer Guide.

  • is_published (Optional[IsPublished], default: None ) –

    Specifies whether to publish the resource. When true, the resource is saved in published (ACTIVE) state. When false, it is saved as a draft (DRAFT). Default: true.

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

    The tags to add to the resource when it is created.

Raises:

  • AccessDeniedException –

    You do not have sufficient permissions to perform this action.

  • ConflictException –

    The request conflicts with the current state of the resource. For example, the resource was modified concurrently, or it is in a state that does not allow the requested operation.

  • InternalServerException –

    The request processing failed because of an internal error in the service. This is a retryable error.

  • ServiceQuotaExceededException –

    The request would exceed a service quota.

  • ServiceUnavailableException –

    The service is temporarily unavailable. This is a retryable error.

  • TagPolicyViolationException –

    The request violates a tag policy that is in effect for the account or organization.

  • ThrottlingException –

    The request was denied because of request throttling. Reduce your request rate and try again.

  • ValidationException –

    The request failed validation. For details, see the reason and fieldList members of the response.

  • UnknownServiceError –

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

Examples:

Create a WAF rule Creates a new WAF inspection rule in draft state.

>>> await client.create_rule(client_token='550e8400-e29b-41d4-a716-446655440000', rule_name='block-known-bad-ips', firewall_type='WAF', rule_type='INSPECTION', rule_description='Blocks requests from known malicious IP addresses', configuration={}, is_published=False)
Source code in docs_src/capo_network_security_manager/_services/async_network_security_manager.py
async def create_rule(
    self,
    rule_name: "capo_network_security_manager.types.rule_name.RuleName",
    firewall_type: "capo_network_security_manager.types.rule_firewall_type.RuleFirewallType",
    rule_type: "capo_network_security_manager.types.rule_type.RuleType",
    configuration: "capo_network_security_manager.types.json_document.JsonDocument",
    *,
    config_overrides: Optional[AsyncNetworkSecurityManagerClientConfig] = None,
    client_token: Optional[
        "capo_network_security_manager.types.idempotency_token.IdempotencyToken"
    ] = None,
    rule_description: Optional[
        "capo_network_security_manager.types.description.Description"
    ] = None,
    is_published: Optional[
        "capo_network_security_manager.types.is_published.IsPublished"
    ] = None,
    tags: Optional["capo_network_security_manager.types.tag_map.TagMap"] = None,
) -> "capo_network_security_manager.types.create_rule_output.CreateRuleOutput":
    """<p>Creates a rule. A rule defines a network security configuration to enforce, such as an AWS WAF rule group or configuration data. Use <code>isPublished</code> to create the rule in published (<code>ACTIVE</code>) or draft (<code>DRAFT</code>) state.</p>

    Args:
        client_token: <p>A unique, case-sensitive token that you provide to ensure that the operation completes no more than one time. If you retry a request with the same client token and the same parameters, the service returns the result of the original successful request.</p>
        rule_name: <p>The name of the rule.</p>
        firewall_type: <p>The firewall type associated with the resource.</p>
        rule_type: <p>The type of the rule. <code>CONFIGURATION</code> rules contain firewall settings, and <code>INSPECTION</code> rules contain rule groups.</p>
        rule_description: <p>A description of the rule.</p>
        configuration: <p>The firewall configuration for the rule, as a JSON document. The structure depends on the rule's firewall type and rule type. For an AWS WAF <code>INSPECTION</code> rule, provide an AWS WAF rule group. For an AWS WAF <code>CONFIGURATION</code> rule, provide a single web ACL setting, such as <code>DefaultAction</code> or <code>VisibilityConfig</code>; use <code>wafConfigDataType</code> to declare which setting the document contains. For the schema of each setting and complete examples, see <a href="https://docs.aws.amazon.com/network-security-manager/latest/devguide/what-is.html">Writing rule configurations</a> in the <i>AWS Network Security Manager Developer Guide</i>.</p>
        is_published: <p>Specifies whether to publish the resource. When <code>true</code>, the resource is saved in published (<code>ACTIVE</code>) state. When <code>false</code>, it is saved as a draft (<code>DRAFT</code>). Default: <code>true</code>.</p>
        tags: <p>The tags to add to the resource when it is created.</p>

    Raises:
        capo_network_security_manager.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient permissions to perform this action.</p>
        capo_network_security_manager.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of the resource. For example, the resource was modified concurrently, or it is in a state that does not allow the requested operation.</p>
        capo_network_security_manager.errors.internal_server_exception.InternalServerException: <p>The request processing failed because of an internal error in the service. This is a retryable error.</p>
        capo_network_security_manager.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed a service quota.</p>
        capo_network_security_manager.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is temporarily unavailable. This is a retryable error.</p>
        capo_network_security_manager.errors.tag_policy_violation_exception.TagPolicyViolationException: <p>The request violates a tag policy that is in effect for the account or organization.</p>
        capo_network_security_manager.errors.throttling_exception.ThrottlingException: <p>The request was denied because of request throttling. Reduce your request rate and try again.</p>
        capo_network_security_manager.errors.validation_exception.ValidationException: <p>The request failed validation. For details, see the <code>reason</code> and <code>fieldList</code> members of the response.</p>
        capo_network_security_manager.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Create a WAF rule
        Creates a new WAF inspection rule in draft state.

        >>> await client.create_rule(client_token='550e8400-e29b-41d4-a716-446655440000', rule_name='block-known-bad-ips', firewall_type='WAF', rule_type='INSPECTION', rule_description='Blocks requests from known malicious IP addresses', configuration={}, is_published=False)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_network_security_manager.types.create_rule_input.CreateRuleInput]",
    ) -> AsyncOperationResponse[
        "capo_network_security_manager.types.create_rule_output.CreateRuleOutput"
    ]:
        import capo_network_security_manager._operations.piccolo_customer_api_service.create_rule

        (
            output,
            http_response,
        ) = await capo_network_security_manager._operations.piccolo_customer_api_service.create_rule.async_create_rule(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateRule")
    )
    input_: capo_network_security_manager.types.create_rule_input.CreateRuleInput = {
        "rule_name": rule_name,
        "firewall_type": firewall_type,
        "rule_type": rule_type,
        "configuration": configuration,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if rule_description is not None:
        input_["rule_description"] = rule_description
    if is_published is not None:
        input_["is_published"] = is_published
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output