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 Builder
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.
session_id(impl Into<String>)
/set_session_id(Option<String>)
:
required: falseCreates a stateful session or identifies an existing one. You can do one of the following:
-
Create a stateful session by specifying the value
NEW_SESSION
. -
Send your request to an existing stateful session by specifying the ID of that session.
With a stateful session, you can send multiple requests to a stateful model. When you create a session with a stateful model, the model must create the session ID and set the expiration time. The model must also provide that information in the response to your request. You can get the ID and timestamp from the
NewSessionId
response parameter. For any subsequent request where you specify that session ID, SageMaker routes the request to the same instance that supports the session.-
- 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.
new_session_id(Option<String>)
:If you created a stateful session with your request, the ID and expiration time that the model assigns to that session.
closed_session_id(Option<String>)
:If you closed a stateful session with your request, the ID of that session.
- 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.
session_id(impl Into<String>)
/set_session_id(Option<String>)
:
required: falseThe ID of a stateful session to handle your request.
You can’t create a stateful session by using the
InvokeEndpointWithResponseStream
action. Instead, you can create one by using theInvokeEndpoint
NEW_SESSION
for theSessionId
request parameter. The response to that request provides the session ID for theNewSessionId
response parameter.
- 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);