Skip to content

update_policy

update_policy(
    policy_identifier: PolicyIdentifier,
    update_token: UpdateToken,
    is_published: IsPublished,
    *,
    config_overrides: Optional[NetworkSecurityManagerClientConfig] = None,
    policy_description: Optional[Description] = None,
    priority: Optional[Priority] = None,
    associated_template_and_rule_list: Optional[TemplateAndRuleReferenceList] = None,
    policy_configuration: Optional[PolicyConfiguration] = None,
    client_token: Optional[IdempotencyToken] = None,
) -> UpdatePolicyOutput

Updates the specified policy. To prevent conflicting concurrent updates, provide the current updateToken. Use isPublished to publish the update or keep the policy as a draft.

Parameters:

  • policy_identifier (PolicyIdentifier) –

    The identifier of the policy. This is the policy's Amazon Resource Name (ARN).

  • update_token (UpdateToken) –

    A token used for optimistic concurrency control. Each read and write returns an updateToken. Provide the most recent value on your next update to detect and prevent conflicting concurrent modifications.

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

    A description of the policy.

  • priority (Optional[Priority], default: None ) –

    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.

  • policy_configuration (Optional[PolicyConfiguration], default: None ) –

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

  • is_published (IsPublished) –

    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).

  • 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.

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.

  • ResourceNotFoundException –

    The specified resource was not found. Verify that the resource identifier is correct and that the resource exists, then try your request again.

  • ServiceQuotaExceededException –

    The request would exceed a service quota.

  • 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:

Update a policy and publish it Updates the policy's description, priority, and configuration and publishes the change. The updateToken from the most recent read is required for optimistic locking.

>>> client.update_policy(policy_identifier='arn:aws:network-security-manager:us-east-1:123456789012:policy:xyz789', update_token='e3f4a5b6-6c7d-4e8f-9a0b-0c1d2e3f4a5b', policy_description='WAF policy for web application protection - updated', priority=2, associated_template_and_rule_list=[{'templateIdentifier': 'arn:aws:network-security-manager:us-east-1:123456789012:template:xyz789'}], policy_configuration={'remediationEnabled': True, 'resourcesCleanUp': False, 'wafConfig': {'existingCustomerWebACLResolution': 'NO_REMEDIATION', 'conflictResolution': 'MERGE_WHERE_APPLICABLE'}}, is_published=True)
Source code in docs_src/capo_network_security_manager/_services/network_security_manager.py
def update_policy(
    self,
    policy_identifier: "capo_network_security_manager.types.policy_identifier.PolicyIdentifier",
    update_token: "capo_network_security_manager.types.update_token.UpdateToken",
    is_published: "capo_network_security_manager.types.is_published.IsPublished",
    *,
    config_overrides: Optional[NetworkSecurityManagerClientConfig] = None,
    policy_description: Optional[
        "capo_network_security_manager.types.description.Description"
    ] = None,
    priority: Optional[
        "capo_network_security_manager.types.priority.Priority"
    ] = None,
    associated_template_and_rule_list: Optional[
        "capo_network_security_manager.types.template_and_rule_reference_list.TemplateAndRuleReferenceList"
    ] = None,
    policy_configuration: Optional[
        "capo_network_security_manager.types.policy_configuration.PolicyConfiguration"
    ] = None,
    client_token: Optional[
        "capo_network_security_manager.types.idempotency_token.IdempotencyToken"
    ] = None,
) -> "capo_network_security_manager.types.update_policy_output.UpdatePolicyOutput":
    """<p>Updates the specified policy. To prevent conflicting concurrent updates, provide the current <code>updateToken</code>. Use <code>isPublished</code> to publish the update or keep the policy as a draft.</p>

    Args:
        policy_identifier: <p>The identifier of the policy. This is the policy's Amazon Resource Name (ARN).</p>
        update_token: <p>A token used for optimistic concurrency control. Each read and write returns an <code>updateToken</code>. Provide the most recent value on your next update to detect and prevent conflicting concurrent modifications.</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>
        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>).</p>
        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>

    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.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource was not found. Verify that the resource identifier is correct and that the resource exists, then try your request again.</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.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:
        Update a policy and publish it
        Updates the policy's description, priority, and configuration and publishes the change. The updateToken from the most recent read is required for optimistic locking.

        >>> client.update_policy(policy_identifier='arn:aws:network-security-manager:us-east-1:123456789012:policy:xyz789', update_token='e3f4a5b6-6c7d-4e8f-9a0b-0c1d2e3f4a5b', policy_description='WAF policy for web application protection - updated', priority=2, associated_template_and_rule_list=[{'templateIdentifier': 'arn:aws:network-security-manager:us-east-1:123456789012:template:xyz789'}], policy_configuration={'remediationEnabled': True, 'resourcesCleanUp': False, 'wafConfig': {'existingCustomerWebACLResolution': 'NO_REMEDIATION', 'conflictResolution': 'MERGE_WHERE_APPLICABLE'}}, is_published=True)
    """

    def _handler(
        req: "OperationRequest[capo_network_security_manager.types.update_policy_input.UpdatePolicyInput]",
    ) -> OperationResponse[
        "capo_network_security_manager.types.update_policy_output.UpdatePolicyOutput"
    ]:
        import capo_network_security_manager._operations.piccolo_customer_api_service.update_policy

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("UpdatePolicy")
    )
    input_: capo_network_security_manager.types.update_policy_input.UpdatePolicyInput = {
        "policy_identifier": policy_identifier,
        "update_token": update_token,
        "is_published": is_published,
    }
    if policy_description is not None:
        input_["policy_description"] = policy_description
    if priority is not None:
        input_["priority"] = priority
    if associated_template_and_rule_list is not None:
        input_["associated_template_and_rule_list"] = (
            associated_template_and_rule_list
        )
    if policy_configuration is not None:
        input_["policy_configuration"] = policy_configuration
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

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