Skip to content

put_endpoint_policy

put_endpoint_policy(
    *,
    config_overrides: Optional[SageMakerClientConfig] = None,
    endpoint_name: Optional[EndpointName] = None,
    resource_policy: Optional[EndpointPolicyDocument] = None,
) -> PutEndpointPolicyResponse

Attaches a resource-based policy to an endpoint. With an endpoint policy, you can allow other Amazon Web Services accounts to send requests to your endpoint, or to inference components on it, through an inference router. The policy that you specify replaces the endpoint's existing policy, if it has one.

You can't attach a policy to an endpoint whose status is Deleting or Failed. SageMaker AI rejects a policy that doesn't follow the endpoint policy rules. For information about the policy rules, see Use destinations in other accounts.

Policy changes typically take effect within 30 seconds, and can take up to 5 minutes. If you delete the endpoint, its policy is also deleted, and a new endpoint with the same name has no policy.

Parameters:

Raises:

Source code in docs_src/capo_sagemaker/_services/sage_maker.py
def put_endpoint_policy(
    self,
    *,
    config_overrides: Optional[SageMakerClientConfig] = None,
    endpoint_name: Optional[
        "capo_sagemaker.types.endpoint_name.EndpointName"
    ] = None,
    resource_policy: Optional[
        "capo_sagemaker.types.endpoint_policy_document.EndpointPolicyDocument"
    ] = None,
) -> "capo_sagemaker.types.put_endpoint_policy_response.PutEndpointPolicyResponse":
    """<p>Attaches a resource-based policy to an endpoint. With an endpoint policy, you can allow other Amazon Web Services accounts to send requests to your endpoint, or to inference components on it, through an inference router. The policy that you specify replaces the endpoint's existing policy, if it has one.</p> <p>You can't attach a policy to an endpoint whose status is <code>Deleting</code> or <code>Failed</code>. SageMaker AI rejects a policy that doesn't follow the endpoint policy rules. For information about the policy rules, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/inference-router-cross-account.html">Use destinations in other accounts</a>.</p> <p>Policy changes typically take effect within 30 seconds, and can take up to 5 minutes. If you delete the endpoint, its policy is also deleted, and a new endpoint with the same name has no policy.</p>

    Args:
        endpoint_name: <p>The name of the endpoint. The endpoint must be in your account and in the current Amazon Web Services Region.</p>
        resource_policy: <p>The endpoint policy, as a JSON policy document. The policy can contain only ASCII characters. For information about the policy rules, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/inference-router-cross-account.html">Use destinations in other accounts</a>.</p>

    Raises:
        capo_sagemaker.errors.resource_not_found.ResourceNotFound: <p>Resource being access is not found.</p>
        capo_sagemaker.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_sagemaker.types.put_endpoint_policy_request.PutEndpointPolicyRequest]",
    ) -> OperationResponse[
        "capo_sagemaker.types.put_endpoint_policy_response.PutEndpointPolicyResponse"
    ]:
        import capo_sagemaker._operations.sage_maker.put_endpoint_policy

        output, http_response = (
            capo_sagemaker._operations.sage_maker.put_endpoint_policy.put_endpoint_policy(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutEndpointPolicy")
    )
    input_: capo_sagemaker.types.put_endpoint_policy_request.PutEndpointPolicyRequest = {}
    if endpoint_name is not None:
        input_["endpoint_name"] = endpoint_name
    if resource_policy is not None:
        input_["resource_policy"] = resource_policy

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