Skip to content

update_policy

update_policy(
    policy_store_id: PolicyStoreId,
    policy_id: PolicyId,
    *,
    config_overrides: Optional[VerifiedPermissionsClientConfig] = None,
    definition: Optional[UpdatePolicyDefinition] = None,
    name: Optional[PolicyName] = None,
) -> UpdatePolicyOutput

Modifies a Cedar static policy in the specified policy store. You can change only certain elements of the UpdatePolicyDefinition parameter. You can directly update only static policies. To change a template-linked policy, you must update the template instead, using UpdatePolicyTemplate.

  • If policy validation is enabled in the policy store, then updating a static policy causes Verified Permissions to validate the policy against the schema in the policy store. If the updated static policy doesn't pass validation, the operation fails and the update isn't stored.

  • When you edit a static policy, you can change only certain elements of a static policy:

    • The action referenced by the policy.

    • A condition clause, such as when and unless.

    You can't change these elements of a static policy:

    • Changing a policy from a static policy to a template-linked policy.

    • Changing the effect of a static policy from permit or forbid.

    • The principal referenced by a static policy.

    • The resource referenced by a static policy.

  • To update a template-linked policy, you must update the template instead.

Verified Permissions is eventually consistent . It can take a few seconds for a new or changed element to propagate through the service and be visible in the results of other Verified Permissions operations.

Parameters:

  • policy_store_id (PolicyStoreId) –

    Specifies the ID of the policy store that contains the policy that you want to update.

    To specify a policy store, use its ID or alias name. When using an alias name, prefix it with policy-store-alias/. For example:

    • ID: PSEXAMPLEabcdefg111111

    • Alias name: policy-store-alias/example-policy-store

    To view aliases, use ListPolicyStoreAliases.

  • policy_id (PolicyId) –

    Specifies the ID of the policy that you want to update. To find this value, you can use ListPolicies.

    You can use the policy name in place of the policy ID. When using a name, prefix it with name/. For example:

    • ID: SPEXAMPLEabcdefg111111

    • Name: name/example-policy

  • definition (Optional[UpdatePolicyDefinition], default: None ) –

    Specifies the updated policy content that you want to replace on the specified policy. The content must be valid Cedar policy language text.

    If you don't specify this parameter, the existing policy definition remains unchanged.

    You can change only the following elements from the policy definition:

    • The action referenced by the policy.

    • Any conditional clauses, such as when or unless clauses.

    You can't change the following elements:

    • Changing from static to templateLinked.

    • Changing the effect of the policy from permit or forbid.

    • The principal referenced by the policy.

    • The resource referenced by the policy.

  • name (Optional[PolicyName], default: None ) –

    Specifies a name for the policy that is unique among all policies within the policy store. You can use the name in place of the policy ID in API operations that reference the policy. The name must be prefixed with name/.

    If you don't include the name in an update request, the existing name is unchanged. To remove a name, set it to an empty string ("").

    If you specify a name that is already associated with another policy in the policy store, you receive a ConflictException error.

Raises:

  • AccessDeniedException –

    You don't have sufficient access to perform this action.

  • InternalServerException –

    The request failed because of an internal error. Try your request again later

  • ThrottlingException –

    The request failed because it exceeded a throttling quota.

  • ValidationException –

    The request failed because one or more input parameters don't satisfy their constraint requirements. The output is provided as a list of fields and a reason for each field that isn't valid.

    The possible reasons include the following:

    • UnrecognizedEntityType

      The policy includes an entity type that isn't found in the schema.

    • UnrecognizedActionId

      The policy includes an action id that isn't found in the schema.

    • InvalidActionApplication

      The policy includes an action that, according to the schema, doesn't support the specified principal and resource.

    • UnexpectedType

      The policy included an operand that isn't a valid type for the specified operation.

    • IncompatibleTypes

      The types of elements included in a set, or the types of expressions used in an if...then...else clause aren't compatible in this context.

    • MissingAttribute

      The policy attempts to access a record or entity attribute that isn't specified in the schema. Test for the existence of the attribute first before attempting to access its value. For more information, see the has (presence of attribute test) operator in the Cedar Policy Language Guide.

    • UnsafeOptionalAttributeAccess

      The policy attempts to access a record or entity attribute that is optional and isn't guaranteed to be present. Test for the existence of the attribute first before attempting to access its value. For more information, see the has (presence of attribute test) operator in the Cedar Policy Language Guide.

    • ImpossiblePolicy

      Cedar has determined that a policy condition always evaluates to false. If the policy is always false, it can never apply to any query, and so it can never affect an authorization decision.

    • WrongNumberArguments

      The policy references an extension type with the wrong number of arguments.

    • FunctionArgumentValidationError

      Cedar couldn't parse the argument passed to an extension type. For example, a string that is to be parsed as an IPv4 address can contain only digits and the period character.

  • ConflictException –

    The request failed because another request to modify a resource occurred at the same time.

  • ResourceNotFoundException –

    The request failed because it references a resource that doesn't exist.

  • ServiceQuotaExceededException –

    The request failed because it would cause a service quota to be exceeded.

  • UnknownServiceError –

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

Examples:

UpdatePolicy The following example replaces the definition of the specified static policy with a new one.

>>> client.update_policy(policy_store_id='C7v5xMplfFH3i3e4Jrzb1a', policy_id='9wYxMpljbbZQb5fcZHyJhY', definition={'static': {'statement': 'permit(principal, action, resource in Album::"public_folder");'}}, name='name/example-policy-2')
Source code in docs_src/capo_verifiedpermissions/_services/verified_permissions.py
def update_policy(
    self,
    policy_store_id: "capo_verifiedpermissions.types.policy_store_id.PolicyStoreId",
    policy_id: "capo_verifiedpermissions.types.policy_id.PolicyId",
    *,
    config_overrides: Optional[VerifiedPermissionsClientConfig] = None,
    definition: Optional[
        "capo_verifiedpermissions.types.update_policy_definition.UpdatePolicyDefinition"
    ] = None,
    name: Optional["capo_verifiedpermissions.types.policy_name.PolicyName"] = None,
) -> "capo_verifiedpermissions.types.update_policy_output.UpdatePolicyOutput":
    """<p>Modifies a Cedar static policy in the specified policy store. You can change only certain elements of the <a href="https://docs.aws.amazon.com/verifiedpermissions/latest/apireference/API_UpdatePolicyInput.html#amazonverifiedpermissions-UpdatePolicy-request-UpdatePolicyDefinition">UpdatePolicyDefinition</a> parameter. You can directly update only static policies. To change a template-linked policy, you must update the template instead, using <a href="https://docs.aws.amazon.com/verifiedpermissions/latest/apireference/API_UpdatePolicyTemplate.html">UpdatePolicyTemplate</a>.</p> <note> <ul> <li> <p>If policy validation is enabled in the policy store, then updating a static policy causes Verified Permissions to validate the policy against the schema in the policy store. If the updated static policy doesn't pass validation, the operation fails and the update isn't stored.</p> </li> <li> <p>When you edit a static policy, you can change only certain elements of a static policy:</p> <ul> <li> <p>The action referenced by the policy. </p> </li> <li> <p>A condition clause, such as when and unless. </p> </li> </ul> <p>You can't change these elements of a static policy: </p> <ul> <li> <p>Changing a policy from a static policy to a template-linked policy. </p> </li> <li> <p>Changing the effect of a static policy from permit or forbid. </p> </li> <li> <p>The principal referenced by a static policy. </p> </li> <li> <p>The resource referenced by a static policy. </p> </li> </ul> </li> <li> <p>To update a template-linked policy, you must update the template instead. </p> </li> </ul> </note> <note> <p>Verified Permissions is <i> <a href="https://wikipedia.org/wiki/Eventual_consistency">eventually consistent</a> </i>. It can take a few seconds for a new or changed element to propagate through the service and be visible in the results of other Verified Permissions operations.</p> </note>

    Args:
        policy_store_id: <p>Specifies the ID of the policy store that contains the policy that you want to update.</p> <p>To specify a policy store, use its ID or alias name. When using an alias name, prefix it with <code>policy-store-alias/</code>. For example:</p> <ul> <li> <p>ID: <code>PSEXAMPLEabcdefg111111</code> </p> </li> <li> <p>Alias name: <code>policy-store-alias/example-policy-store</code> </p> </li> </ul> <p>To view aliases, use <a href="https://docs.aws.amazon.com/verifiedpermissions/latest/apireference/API_ListPolicyStoreAliases.html">ListPolicyStoreAliases</a>.</p>
        policy_id: <p>Specifies the ID of the policy that you want to update. To find this value, you can use <a href="https://docs.aws.amazon.com/verifiedpermissions/latest/apireference/API_ListPolicies.html">ListPolicies</a>.</p> <p>You can use the policy name in place of the policy ID. When using a name, prefix it with <code>name/</code>. For example:</p> <ul> <li> <p>ID: <code>SPEXAMPLEabcdefg111111</code> </p> </li> <li> <p>Name: <code>name/example-policy</code> </p> </li> </ul>
        definition: <p>Specifies the updated policy content that you want to replace on the specified policy. The content must be valid Cedar policy language text.</p> <p>If you don't specify this parameter, the existing policy definition remains unchanged.</p> <p>You can change only the following elements from the policy definition:</p> <ul> <li> <p>The <code>action</code> referenced by the policy.</p> </li> <li> <p>Any conditional clauses, such as <code>when</code> or <code>unless</code> clauses.</p> </li> </ul> <p>You <b>can't</b> change the following elements:</p> <ul> <li> <p>Changing from <code>static</code> to <code>templateLinked</code>.</p> </li> <li> <p>Changing the effect of the policy from <code>permit</code> or <code>forbid</code>.</p> </li> <li> <p>The <code>principal</code> referenced by the policy.</p> </li> <li> <p>The <code>resource</code> referenced by the policy.</p> </li> </ul>
        name: <p>Specifies a name for the policy that is unique among all policies within the policy store. You can use the name in place of the policy ID in API operations that reference the policy. The name must be prefixed with <code>name/</code>.</p> <note> <p>If you don't include the name in an update request, the existing name is unchanged. To remove a name, set it to an empty string (<code>""</code>).</p> </note> <p>If you specify a name that is already associated with another policy in the policy store, you receive a <code>ConflictException</code> error.</p>

    Raises:
        capo_verifiedpermissions.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this action.</p>
        capo_verifiedpermissions.errors.internal_server_exception.InternalServerException: <p>The request failed because of an internal error. Try your request again later</p>
        capo_verifiedpermissions.errors.throttling_exception.ThrottlingException: <p>The request failed because it exceeded a throttling quota.</p>
        capo_verifiedpermissions.errors.validation_exception.ValidationException: <p>The request failed because one or more input parameters don't satisfy their constraint requirements. The output is provided as a list of fields and a reason for each field that isn't valid.</p> <p>The possible reasons include the following:</p> <ul> <li> <p> <b>UnrecognizedEntityType</b> </p> <p>The policy includes an entity type that isn't found in the schema.</p> </li> <li> <p> <b>UnrecognizedActionId</b> </p> <p>The policy includes an action id that isn't found in the schema.</p> </li> <li> <p> <b>InvalidActionApplication</b> </p> <p>The policy includes an action that, according to the schema, doesn't support the specified principal and resource.</p> </li> <li> <p> <b>UnexpectedType</b> </p> <p>The policy included an operand that isn't a valid type for the specified operation.</p> </li> <li> <p> <b>IncompatibleTypes</b> </p> <p>The types of elements included in a <code>set</code>, or the types of expressions used in an <code>if...then...else</code> clause aren't compatible in this context.</p> </li> <li> <p> <b>MissingAttribute</b> </p> <p>The policy attempts to access a record or entity attribute that isn't specified in the schema. Test for the existence of the attribute first before attempting to access its value. For more information, see the <a href="https://docs.cedarpolicy.com/policies/syntax-operators.html#has-presence-of-attribute-test">has (presence of attribute test) operator</a> in the <i>Cedar Policy Language Guide</i>.</p> </li> <li> <p> <b>UnsafeOptionalAttributeAccess</b> </p> <p>The policy attempts to access a record or entity attribute that is optional and isn't guaranteed to be present. Test for the existence of the attribute first before attempting to access its value. For more information, see the <a href="https://docs.cedarpolicy.com/policies/syntax-operators.html#has-presence-of-attribute-test">has (presence of attribute test) operator</a> in the <i>Cedar Policy Language Guide</i>.</p> </li> <li> <p> <b>ImpossiblePolicy</b> </p> <p>Cedar has determined that a policy condition always evaluates to false. If the policy is always false, it can never apply to any query, and so it can never affect an authorization decision.</p> </li> <li> <p> <b>WrongNumberArguments</b> </p> <p>The policy references an extension type with the wrong number of arguments.</p> </li> <li> <p> <b>FunctionArgumentValidationError</b> </p> <p>Cedar couldn't parse the argument passed to an extension type. For example, a string that is to be parsed as an IPv4 address can contain only digits and the period character.</p> </li> </ul>
        capo_verifiedpermissions.errors.conflict_exception.ConflictException: <p>The request failed because another request to modify a resource occurred at the same time.</p>
        capo_verifiedpermissions.errors.resource_not_found_exception.ResourceNotFoundException: <p>The request failed because it references a resource that doesn't exist.</p>
        capo_verifiedpermissions.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request failed because it would cause a service quota to be exceeded.</p>
        capo_verifiedpermissions.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        UpdatePolicy
        The following example replaces the definition of the specified static policy with a new one.

        >>> client.update_policy(policy_store_id='C7v5xMplfFH3i3e4Jrzb1a', policy_id='9wYxMpljbbZQb5fcZHyJhY', definition={'static': {'statement': 'permit(principal, action, resource in Album::"public_folder");'}}, name='name/example-policy-2')
    """

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

        output, http_response = (
            capo_verifiedpermissions._operations.verified_permissions.update_policy.update_policy(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_verifiedpermissions.types.update_policy_input.UpdatePolicyInput",
    ) -> dict[str, Any]:
        import capo_verifiedpermissions.types.update_policy_input

        return capo_verifiedpermissions.types.update_policy_input.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_verifiedpermissions.types.update_policy_output.UpdatePolicyOutput",
    ) -> dict[str, Any]:
        import capo_verifiedpermissions.types.update_policy_output

        return capo_verifiedpermissions.types.update_policy_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "UpdatePolicy", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_verifiedpermissions.types.update_policy_input.UpdatePolicyInput = {
        "policy_store_id": policy_store_id,
        "policy_id": policy_id,
    }
    if definition is not None:
        input_["definition"] = definition
    if name is not None:
        input_["name"] = name

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