Skip to content

create_policy

create_policy(
    policy_name: PolicyName,
    priority: Priority,
    firewall_type: PolicyFirewallType,
    policy_configuration: PolicyConfiguration,
    *,
    config_overrides: Optional[NetworkSecurityManagerClientConfig] = None,
    client_token: Optional[IdempotencyToken] = None,
    policy_description: Optional[Description] = None,
    associated_template_and_rule_list: Optional[TemplateAndRuleReferenceList] = None,
    is_published: Optional[IsPublished] = None,
    tags: Optional[TagMap] = None,
) -> CreatePolicyOutput

Creates a policy. A policy combines templates and rules with enforcement settings for a firewall type, such as AWS WAF or AWS Shield Advanced. Use isPublished to create the policy 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.

  • policy_name (PolicyName) –

    The name of the policy.

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

    A description of the policy.

  • priority (Priority) –

    The priority of the resource. A lower number indicates a higher priority.

  • associated_template_and_rule_list (Optional[TemplateAndRuleReferenceList], default: None ) –

    The templates and rules to associate with the policy. For AWS WAF policies, specify 1 to 100 templates or rules, of which at most 2 can be templates. For AWS Shield Advanced policies, this list must be empty.

  • firewall_type (PolicyFirewallType) –

    The firewall type associated with the resource.

  • policy_configuration (PolicyConfiguration) –

    The configuration settings that control the policy's behavior, including remediation and firewall-type-specific settings.

  • 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 policy Creates a new WAF policy in draft state with a template association.

>>> client.create_policy(client_token='550e8400-e29b-41d4-a716-446655440002', policy_name='web-app-waf-policy', policy_description='WAF policy for web application protection', firewall_type='WAF', priority=1, associated_template_and_rule_list=[{'templateIdentifier': 'arn:aws:network-security-manager:us-east-1:123456789012:template:xyz789'}], policy_configuration={'remediationEnabled': False, 'resourcesCleanUp': False, 'wafConfig': {'existingCustomerWebACLResolution': 'NO_REMEDIATION', 'conflictResolution': 'MERGE_WHERE_APPLICABLE'}}, is_published=False)
Source code in docs_src/capo_network_security_manager/_services/network_security_manager.py
def create_policy(
    self,
    policy_name: "capo_network_security_manager.types.policy_name.PolicyName",
    priority: "capo_network_security_manager.types.priority.Priority",
    firewall_type: "capo_network_security_manager.types.policy_firewall_type.PolicyFirewallType",
    policy_configuration: "capo_network_security_manager.types.policy_configuration.PolicyConfiguration",
    *,
    config_overrides: Optional[NetworkSecurityManagerClientConfig] = None,
    client_token: Optional[
        "capo_network_security_manager.types.idempotency_token.IdempotencyToken"
    ] = None,
    policy_description: Optional[
        "capo_network_security_manager.types.description.Description"
    ] = None,
    associated_template_and_rule_list: Optional[
        "capo_network_security_manager.types.template_and_rule_reference_list.TemplateAndRuleReferenceList"
    ] = 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_policy_output.CreatePolicyOutput":
    """<p>Creates a policy. A policy combines templates and rules with enforcement settings for a firewall type, such as AWS WAF or AWS Shield Advanced. Use <code>isPublished</code> to create the policy 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>
        policy_name: <p>The name of the policy.</p>
        policy_description: <p>A description of the policy.</p>
        priority: <p>The priority of the resource. A lower number indicates a higher priority.</p>
        associated_template_and_rule_list: <p>The templates and rules to associate with the policy. For AWS WAF policies, specify 1 to 100 templates or rules, of which at most 2 can be templates. For AWS Shield Advanced policies, this list must be empty.</p>
        firewall_type: <p>The firewall type associated with the resource.</p>
        policy_configuration: <p>The configuration settings that control the policy's behavior, including remediation and firewall-type-specific settings.</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 policy
        Creates a new WAF policy in draft state with a template association.

        >>> client.create_policy(client_token='550e8400-e29b-41d4-a716-446655440002', policy_name='web-app-waf-policy', policy_description='WAF policy for web application protection', firewall_type='WAF', priority=1, associated_template_and_rule_list=[{'templateIdentifier': 'arn:aws:network-security-manager:us-east-1:123456789012:template:xyz789'}], policy_configuration={'remediationEnabled': False, 'resourcesCleanUp': False, 'wafConfig': {'existingCustomerWebACLResolution': 'NO_REMEDIATION', 'conflictResolution': 'MERGE_WHERE_APPLICABLE'}}, is_published=False)
    """

    def _handler(
        req: "OperationRequest[capo_network_security_manager.types.create_policy_input.CreatePolicyInput]",
    ) -> OperationResponse[
        "capo_network_security_manager.types.create_policy_output.CreatePolicyOutput"
    ]:
        import capo_network_security_manager._operations.piccolo_customer_api_service.create_policy

        output, http_response = (
            capo_network_security_manager._operations.piccolo_customer_api_service.create_policy.create_policy(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreatePolicy")
    )
    input_: capo_network_security_manager.types.create_policy_input.CreatePolicyInput = {
        "policy_name": policy_name,
        "priority": priority,
        "firewall_type": firewall_type,
        "policy_configuration": policy_configuration,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if policy_description is not None:
        input_["policy_description"] = policy_description
    if associated_template_and_rule_list is not None:
        input_["associated_template_and_rule_list"] = (
            associated_template_and_rule_list
        )
    if is_published is not None:
        input_["is_published"] = is_published
    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