Struct aws_sdk_sagemakerruntime::Client
source · pub struct Client { /* private fields */ }
Expand description
Client for Amazon SageMaker Runtime
Client for invoking operations on Amazon SageMaker Runtime. Each operation on Amazon SageMaker Runtime is a method on this
this struct. .send()
MUST be invoked on the generated operations to dispatch the request to the service.
§Constructing a Client
A Config
is required to construct a client. For most use cases, the aws-config
crate should be used to automatically resolve this config using
aws_config::load_from_env()
, since this will resolve an SdkConfig
which can be shared
across multiple different AWS SDK clients. This config resolution process can be customized
by calling aws_config::from_env()
instead, which returns a ConfigLoader
that uses
the builder pattern to customize the default config.
In the simplest case, creating a client looks as follows:
let config = aws_config::load_from_env().await;
let client = aws_sdk_sagemakerruntime::Client::new(&config);
Occasionally, SDKs may have additional service-specific values that can be set on the Config
that
is absent from SdkConfig
, or slightly different settings for a specific client may be desired.
The Config
struct implements From<&SdkConfig>
, so setting these specific settings can be
done as follows:
let sdk_config = ::aws_config::load_from_env().await;
let config = aws_sdk_sagemakerruntime::config::Builder::from(&sdk_config)
.some_service_specific_setting("value")
.build();
See the aws-config
docs and Config
for more information on customizing configuration.
Note: Client construction is expensive due to connection thread pool initialization, and should be done once at application start-up.
§Using the Client
A client has a function for every operation that can be performed by the service.
For example, the InvokeEndpoint
operation has
a Client::invoke_endpoint
, function which returns a builder for that operation.
The fluent builder ultimately has a send()
function that returns an async future that
returns a result, as illustrated below:
let result = client.invoke_endpoint()
.endpoint_name("example")
.send()
.await;
The underlying HTTP requests that get made by this can be modified with the customize_operation
function on the fluent builder. See the customize
module for more
information.
Implementations§
source§impl Client
impl Client
sourcepub fn invoke_endpoint(&self) -> InvokeEndpointFluentBuilder
pub fn invoke_endpoint(&self) -> InvokeEndpointFluentBuilder
Constructs a fluent builder for the InvokeEndpoint
operation.
- The fluent builder is configurable:
endpoint_name(impl Into<String>)
/set_endpoint_name(Option<String>)
:
required: trueThe name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.
body(Blob)
/set_body(Option<Blob>)
:
required: trueProvides input data, in the format specified in the
ContentType
request header. Amazon SageMaker passes all of the data in the body to the model.For information about the format of the request body, see Common Data Formats-Inference.
content_type(impl Into<String>)
/set_content_type(Option<String>)
:
required: falseThe MIME type of the input data in the request body.
accept(impl Into<String>)
/set_accept(Option<String>)
:
required: falseThe desired MIME type of the inference response from the model container.
custom_attributes(impl Into<String>)
/set_custom_attributes(Option<String>)
:
required: falseProvides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1).
The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with
Trace ID:
in your post-processing function.This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK.
target_model(impl Into<String>)
/set_target_model(Option<String>)
:
required: falseThe model to request for inference when invoking a multi-model endpoint.
target_variant(impl Into<String>)
/set_target_variant(Option<String>)
:
required: falseSpecify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights.
For information about how to use variant targeting to perform a/b testing, see Test models in production
target_container_hostname(impl Into<String>)
/set_target_container_hostname(Option<String>)
:
required: falseIf the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke.
inference_id(impl Into<String>)
/set_inference_id(Option<String>)
:
required: falseIf you provide a value, it is added to the captured data when you enable data capture on the endpoint. For information about data capture, see Capture Data.
enable_explanations(impl Into<String>)
/set_enable_explanations(Option<String>)
:
required: falseAn optional JMESPath expression used to override the
EnableExplanations
parameter of theClarifyExplainerConfig
API. See the EnableExplanations section in the developer guide for more information.inference_component_name(impl Into<String>)
/set_inference_component_name(Option<String>)
:
required: falseIf the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke.
- On success, responds with
InvokeEndpointOutput
with field(s):body(Option<Blob>)
:Includes the inference provided by the model.
For information about the format of the response body, see Common Data Formats-Inference.
If the explainer is activated, the body includes the explanations provided by the model. For more information, see the Response section under Invoke the Endpoint in the Developer Guide.
content_type(Option<String>)
:The MIME type of the inference returned from the model container.
invoked_production_variant(Option<String>)
:Identifies the production variant that was invoked.
custom_attributes(Option<String>)
:Provides additional information in the response about the inference returned by a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to return an ID received in the
CustomAttributes
header of a request or other metadata that a service endpoint was programmed to produce. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). If the customer wants the custom attribute returned, the model must set the custom attribute to be included on the way back.The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with
Trace ID:
in your post-processing function.This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK.
- On failure, responds with
SdkError<InvokeEndpointError>
source§impl Client
impl Client
sourcepub fn invoke_endpoint_async(&self) -> InvokeEndpointAsyncFluentBuilder
pub fn invoke_endpoint_async(&self) -> InvokeEndpointAsyncFluentBuilder
Constructs a fluent builder for the InvokeEndpointAsync
operation.
- The fluent builder is configurable:
endpoint_name(impl Into<String>)
/set_endpoint_name(Option<String>)
:
required: trueThe name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.
content_type(impl Into<String>)
/set_content_type(Option<String>)
:
required: falseThe MIME type of the input data in the request body.
accept(impl Into<String>)
/set_accept(Option<String>)
:
required: falseThe desired MIME type of the inference response from the model container.
custom_attributes(impl Into<String>)
/set_custom_attributes(Option<String>)
:
required: falseProvides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1).
The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with
Trace ID:
in your post-processing function.This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK.
inference_id(impl Into<String>)
/set_inference_id(Option<String>)
:
required: falseThe identifier for the inference request. Amazon SageMaker will generate an identifier for you if none is specified.
input_location(impl Into<String>)
/set_input_location(Option<String>)
:
required: trueThe Amazon S3 URI where the inference request payload is stored.
request_ttl_seconds(i32)
/set_request_ttl_seconds(Option<i32>)
:
required: falseMaximum age in seconds a request can be in the queue before it is marked as expired. The default is 6 hours, or 21,600 seconds.
invocation_timeout_seconds(i32)
/set_invocation_timeout_seconds(Option<i32>)
:
required: falseMaximum amount of time in seconds a request can be processed before it is marked as expired. The default is 15 minutes, or 900 seconds.
- On success, responds with
InvokeEndpointAsyncOutput
with field(s):inference_id(Option<String>)
:Identifier for an inference request. This will be the same as the
InferenceId
specified in the input. Amazon SageMaker will generate an identifier for you if you do not specify one.output_location(Option<String>)
:The Amazon S3 URI where the inference response payload is stored.
failure_location(Option<String>)
:The Amazon S3 URI where the inference failure response payload is stored.
- On failure, responds with
SdkError<InvokeEndpointAsyncError>
source§impl Client
impl Client
sourcepub fn invoke_endpoint_with_response_stream(
&self
) -> InvokeEndpointWithResponseStreamFluentBuilder
pub fn invoke_endpoint_with_response_stream( &self ) -> InvokeEndpointWithResponseStreamFluentBuilder
Constructs a fluent builder for the InvokeEndpointWithResponseStream
operation.
- The fluent builder is configurable:
endpoint_name(impl Into<String>)
/set_endpoint_name(Option<String>)
:
required: trueThe name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.
body(Blob)
/set_body(Option<Blob>)
:
required: trueProvides input data, in the format specified in the
ContentType
request header. Amazon SageMaker passes all of the data in the body to the model.For information about the format of the request body, see Common Data Formats-Inference.
content_type(impl Into<String>)
/set_content_type(Option<String>)
:
required: falseThe MIME type of the input data in the request body.
accept(impl Into<String>)
/set_accept(Option<String>)
:
required: falseThe desired MIME type of the inference response from the model container.
custom_attributes(impl Into<String>)
/set_custom_attributes(Option<String>)
:
required: falseProvides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1).
The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with
Trace ID:
in your post-processing function.This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK.
target_variant(impl Into<String>)
/set_target_variant(Option<String>)
:
required: falseSpecify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights.
For information about how to use variant targeting to perform a/b testing, see Test models in production
target_container_hostname(impl Into<String>)
/set_target_container_hostname(Option<String>)
:
required: falseIf the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke.
inference_id(impl Into<String>)
/set_inference_id(Option<String>)
:
required: falseAn identifier that you assign to your request.
inference_component_name(impl Into<String>)
/set_inference_component_name(Option<String>)
:
required: falseIf the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke for a streaming response.
- On success, responds with
InvokeEndpointWithResponseStreamOutput
with field(s):body(EventReceiver<ResponseStream, ResponseStreamError>)
:A stream of payload parts. Each part contains a portion of the response for a streaming inference request.
content_type(Option<String>)
:The MIME type of the inference returned from the model container.
invoked_production_variant(Option<String>)
:Identifies the production variant that was invoked.
custom_attributes(Option<String>)
:Provides additional information in the response about the inference returned by a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to return an ID received in the
CustomAttributes
header of a request or other metadata that a service endpoint was programmed to produce. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). If the customer wants the custom attribute returned, the model must set the custom attribute to be included on the way back.The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with
Trace ID:
in your post-processing function.This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK.
- On failure, responds with
SdkError<InvokeEndpointWithResponseStreamError>
source§impl Client
impl Client
sourcepub fn from_conf(conf: Config) -> Self
pub fn from_conf(conf: Config) -> Self
Creates a new client from the service Config
.
§Panics
This method will panic in the following cases:
- Retries or timeouts are enabled without a
sleep_impl
configured. - Identity caching is enabled without a
sleep_impl
andtime_source
configured. - No
behavior_version
is provided.
The panic message for each of these will have instructions on how to resolve them.
source§impl Client
impl Client
sourcepub fn new(sdk_config: &SdkConfig) -> Self
pub fn new(sdk_config: &SdkConfig) -> Self
Creates a new client from an SDK Config.
§Panics
- This method will panic if the
sdk_config
is missing an async sleep implementation. If you experience this panic, set thesleep_impl
on the Config passed into this function to fix it. - This method will panic if the
sdk_config
is missing an HTTP connector. If you experience this panic, set thehttp_connector
on the Config passed into this function to fix it. - This method will panic if no
BehaviorVersion
is provided. If you experience this panic, setbehavior_version
on the Config or enable thebehavior-version-latest
Cargo feature.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more