From fd476fd176f5a8ebda9f7dedf9e5d402c6b4f328 Mon Sep 17 00:00:00 2001 From: awsmobilesdk Date: Wed, 29 Nov 2023 18:55:27 +0000 Subject: [PATCH] feat(AWSSageMakerRuntime): update models to latest --- .../AWSSageMakerRuntimeModel.h | 142 ++++++++++++- .../AWSSageMakerRuntimeModel.m | 78 +++++++ .../AWSSageMakerRuntimeResources.m | 192 +++++++++++++++++- .../AWSSageMakerRuntimeService.h | 29 ++- .../AWSSageMakerRuntimeService.m | 25 +++ .../AWSGeneralSageMakerRuntimeTests.m | 48 +++++ .../AWSSageMakerRuntimeNSSecureCodingTests.m | 20 ++ 7 files changed, 517 insertions(+), 17 deletions(-) diff --git a/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.h b/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.h index 05783a2465f..2cdfa7a2dd0 100644 --- a/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.h +++ b/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.h @@ -25,8 +25,10 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { AWSSageMakerRuntimeErrorUnknown, AWSSageMakerRuntimeErrorInternalDependency, AWSSageMakerRuntimeErrorInternalFailure, + AWSSageMakerRuntimeErrorInternalStreamFailure, AWSSageMakerRuntimeErrorModel, AWSSageMakerRuntimeErrorModelNotReady, + AWSSageMakerRuntimeErrorModelStream, AWSSageMakerRuntimeErrorServiceUnavailable, AWSSageMakerRuntimeErrorValidation, }; @@ -35,6 +37,10 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { @class AWSSageMakerRuntimeInvokeEndpointAsyncOutput; @class AWSSageMakerRuntimeInvokeEndpointInput; @class AWSSageMakerRuntimeInvokeEndpointOutput; +@class AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput; +@class AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput; +@class AWSSageMakerRuntimePayloadPart; +@class AWSSageMakerRuntimeResponseStream; /** @@ -43,7 +49,7 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { /** -

The desired MIME type of the inference in the response.

+

The desired MIME type of the inference response from the model container.

*/ @property (nonatomic, strong) NSString * _Nullable accept; @@ -53,12 +59,12 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { @property (nonatomic, strong) NSString * _Nullable contentType; /** -

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

+

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

*/ @property (nonatomic, strong) NSString * _Nullable customAttributes; /** -

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

+

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

*/ @property (nonatomic, strong) NSString * _Nullable endpointName; @@ -114,7 +120,7 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { /** -

The desired MIME type of the inference in the response.

+

The desired MIME type of the inference response from the model container.

*/ @property (nonatomic, strong) NSString * _Nullable accept; @@ -129,7 +135,7 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { @property (nonatomic, strong) NSString * _Nullable contentType; /** -

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

+

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

*/ @property (nonatomic, strong) NSString * _Nullable customAttributes; @@ -139,10 +145,15 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { @property (nonatomic, strong) NSString * _Nullable enableExplanations; /** -

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

+

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

*/ @property (nonatomic, strong) NSString * _Nullable endpointName; +/** +

If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke.

+ */ +@property (nonatomic, strong) NSString * _Nullable inferenceComponentName; + /**

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

*/ @@ -177,7 +188,7 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { @property (nonatomic, strong) NSData * _Nullable body; /** -

The MIME type of the inference returned in the response body.

+

The MIME type of the inference returned from the model container.

*/ @property (nonatomic, strong) NSString * _Nullable contentType; @@ -193,4 +204,121 @@ typedef NS_ENUM(NSInteger, AWSSageMakerRuntimeErrorType) { @end +/** + + */ +@interface AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput : AWSRequest + + +/** +

The desired MIME type of the inference response from the model container.

+ */ +@property (nonatomic, strong) NSString * _Nullable accept; + +/** +

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

+ */ +@property (nonatomic, strong) NSData * _Nullable body; + +/** +

The MIME type of the input data in the request body.

+ */ +@property (nonatomic, strong) NSString * _Nullable contentType; + +/** +

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

+ */ +@property (nonatomic, strong) NSString * _Nullable customAttributes; + +/** +

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

+ */ +@property (nonatomic, strong) NSString * _Nullable endpointName; + +/** +

If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke for a streaming response.

+ */ +@property (nonatomic, strong) NSString * _Nullable inferenceComponentName; + +/** +

An identifier that you assign to your request.

+ */ +@property (nonatomic, strong) NSString * _Nullable inferenceId; + +/** +

If the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke.

+ */ +@property (nonatomic, strong) NSString * _Nullable targetContainerHostname; + +/** +

Specify 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

+ */ +@property (nonatomic, strong) NSString * _Nullable targetVariant; + +@end + +/** + + */ +@interface AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput : AWSModel + + +/** +

A stream of payload parts. Each part contains a portion of the response for a streaming inference request.

+ */ +@property (nonatomic, strong) AWSSageMakerRuntimeResponseStream * _Nullable body; + +/** +

The MIME type of the inference returned from the model container.

+ */ +@property (nonatomic, strong) NSString * _Nullable contentType; + +/** +

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.

+ */ +@property (nonatomic, strong) NSString * _Nullable customAttributes; + +/** +

Identifies the production variant that was invoked.

+ */ +@property (nonatomic, strong) NSString * _Nullable invokedProductionVariant; + +@end + +/** +

A wrapper for pieces of the payload that's returned in response to a streaming inference request. A streaming inference response consists of one or more payload parts.

+ */ +@interface AWSSageMakerRuntimePayloadPart : AWSModel + + +/** +

A blob that contains part of the response for your streaming inference request.

+ */ +@property (nonatomic, strong) NSData * _Nullable bytes; + +@end + +/** +

A stream of payload parts. Each part contains a portion of the response for a streaming inference request.

+ */ +@interface AWSSageMakerRuntimeResponseStream : AWSModel + + +/** +

The stream processing failed because of an unknown error, exception or failure. Try your request again.

+ */ +@property (nonatomic, strong) _Nullable internalStreamFailure; + +/** +

An error occurred while streaming the response body. This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

+ */ +@property (nonatomic, strong) _Nullable modelStreamError; + +/** +

A wrapper for pieces of the payload that's returned in response to a streaming inference request. A streaming inference response consists of one or more payload parts.

+ */ +@property (nonatomic, strong) AWSSageMakerRuntimePayloadPart * _Nullable payloadPart; + +@end + NS_ASSUME_NONNULL_END diff --git a/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.m b/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.m index 8949e859bdb..11f14b558ed 100644 --- a/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.m +++ b/AWSSageMakerRuntime/AWSSageMakerRuntimeModel.m @@ -69,6 +69,7 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey { @"customAttributes" : @"CustomAttributes", @"enableExplanations" : @"EnableExplanations", @"endpointName" : @"EndpointName", + @"inferenceComponentName" : @"InferenceComponentName", @"inferenceId" : @"InferenceId", @"targetContainerHostname" : @"TargetContainerHostname", @"targetModel" : @"TargetModel", @@ -94,3 +95,80 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey { } @end + +@implementation AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput + ++ (BOOL)supportsSecureCoding { + return YES; +} + ++ (NSDictionary *)JSONKeyPathsByPropertyKey { + return @{ + @"accept" : @"Accept", + @"body" : @"Body", + @"contentType" : @"ContentType", + @"customAttributes" : @"CustomAttributes", + @"endpointName" : @"EndpointName", + @"inferenceComponentName" : @"InferenceComponentName", + @"inferenceId" : @"InferenceId", + @"targetContainerHostname" : @"TargetContainerHostname", + @"targetVariant" : @"TargetVariant", + }; +} + +@end + +@implementation AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput + ++ (BOOL)supportsSecureCoding { + return YES; +} + ++ (NSDictionary *)JSONKeyPathsByPropertyKey { + return @{ + @"body" : @"Body", + @"contentType" : @"ContentType", + @"customAttributes" : @"CustomAttributes", + @"invokedProductionVariant" : @"InvokedProductionVariant", + }; +} + ++ (NSValueTransformer *)bodyJSONTransformer { + return [NSValueTransformer awsmtl_JSONDictionaryTransformerWithModelClass:[AWSSageMakerRuntimeResponseStream class]]; +} + +@end + +@implementation AWSSageMakerRuntimePayloadPart + ++ (BOOL)supportsSecureCoding { + return YES; +} + ++ (NSDictionary *)JSONKeyPathsByPropertyKey { + return @{ + @"bytes" : @"Bytes", + }; +} + +@end + +@implementation AWSSageMakerRuntimeResponseStream + ++ (BOOL)supportsSecureCoding { + return YES; +} + ++ (NSDictionary *)JSONKeyPathsByPropertyKey { + return @{ + @"internalStreamFailure" : @"InternalStreamFailure", + @"modelStreamError" : @"ModelStreamError", + @"payloadPart" : @"PayloadPart", + }; +} + ++ (NSValueTransformer *)payloadPartJSONTransformer { + return [NSValueTransformer awsmtl_JSONDictionaryTransformerWithModelClass:[AWSSageMakerRuntimePayloadPart class]]; +} + +@end diff --git a/AWSSageMakerRuntime/AWSSageMakerRuntimeResources.m b/AWSSageMakerRuntime/AWSSageMakerRuntimeResources.m index bb033e14b9d..428e4416f0b 100644 --- a/AWSSageMakerRuntime/AWSSageMakerRuntimeResources.m +++ b/AWSSageMakerRuntime/AWSSageMakerRuntimeResources.m @@ -102,7 +102,25 @@ - (NSString *)definitionString { {\"shape\":\"ServiceUnavailable\"},\ {\"shape\":\"ValidationError\"}\ ],\ - \"documentation\":\"

After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.

Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointAsync are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

\"\ + \"documentation\":\"

After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.

Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointAsync are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

\"\ + },\ + \"InvokeEndpointWithResponseStream\":{\ + \"name\":\"InvokeEndpointWithResponseStream\",\ + \"http\":{\ + \"method\":\"POST\",\ + \"requestUri\":\"/endpoints/{EndpointName}/invocations-response-stream\"\ + },\ + \"input\":{\"shape\":\"InvokeEndpointWithResponseStreamInput\"},\ + \"output\":{\"shape\":\"InvokeEndpointWithResponseStreamOutput\"},\ + \"errors\":[\ + {\"shape\":\"InternalFailure\"},\ + {\"shape\":\"ServiceUnavailable\"},\ + {\"shape\":\"ValidationError\"},\ + {\"shape\":\"ModelError\"},\ + {\"shape\":\"ModelStreamError\"},\ + {\"shape\":\"InternalStreamFailure\"}\ + ],\ + \"documentation\":\"

Invokes a model at the specified endpoint to return the inference response as a stream. The inference stream provides the response payload incrementally as a series of parts. Before you can get an inference stream, you must have access to a model that's deployed using Amazon SageMaker hosting services, and the container for that model must support inference streaming.

For more information that can help you use this API, see the following sections in the Amazon SageMaker Developer Guide:

Before you can use this operation, your IAM permissions must allow the sagemaker:InvokeEndpoint action. For more information about Amazon SageMaker actions for IAM policies, see Actions, resources, and condition keys for Amazon SageMaker in the IAM Service Authorization Reference.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointWithResponseStream are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

\"\ }\ },\ \"shapes\":{\ @@ -128,11 +146,17 @@ - (NSString *)definitionString { \"max\":63,\ \"pattern\":\"^[a-zA-Z0-9](-*[a-zA-Z0-9])*\"\ },\ + \"ErrorCode\":{\"type\":\"string\"},\ \"Header\":{\ \"type\":\"string\",\ \"max\":1024,\ \"pattern\":\"\\\\p{ASCII}*\"\ },\ + \"InferenceComponentHeader\":{\ + \"type\":\"string\",\ + \"max\":63,\ + \"pattern\":\"^[a-zA-Z0-9]([\\\\-a-zA-Z0-9]*[a-zA-Z0-9])?$\"\ + },\ \"InferenceId\":{\ \"type\":\"string\",\ \"max\":64,\ @@ -167,6 +191,16 @@ - (NSString *)definitionString { \"fault\":true,\ \"synthetic\":true\ },\ + \"InternalStreamFailure\":{\ + \"type\":\"structure\",\ + \"members\":{\ + \"Message\":{\"shape\":\"Message\"}\ + },\ + \"documentation\":\"

The stream processing failed because of an unknown error, exception or failure. Try your request again.

\",\ + \"exception\":true,\ + \"fault\":true,\ + \"synthetic\":true\ + },\ \"InvocationTimeoutSecondsHeader\":{\ \"type\":\"integer\",\ \"max\":3600,\ @@ -181,7 +215,7 @@ - (NSString *)definitionString { \"members\":{\ \"EndpointName\":{\ \"shape\":\"EndpointName\",\ - \"documentation\":\"

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

\",\ + \"documentation\":\"

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

\",\ \"location\":\"uri\",\ \"locationName\":\"EndpointName\"\ },\ @@ -193,13 +227,13 @@ - (NSString *)definitionString { },\ \"Accept\":{\ \"shape\":\"Header\",\ - \"documentation\":\"

The desired MIME type of the inference in the response.

\",\ + \"documentation\":\"

The desired MIME type of the inference response from the model container.

\",\ \"location\":\"header\",\ \"locationName\":\"X-Amzn-SageMaker-Accept\"\ },\ \"CustomAttributes\":{\ \"shape\":\"CustomAttributesHeader\",\ - \"documentation\":\"

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

\",\ + \"documentation\":\"

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

\",\ \"location\":\"header\",\ \"locationName\":\"X-Amzn-SageMaker-Custom-Attributes\"\ },\ @@ -259,7 +293,7 @@ - (NSString *)definitionString { \"members\":{\ \"EndpointName\":{\ \"shape\":\"EndpointName\",\ - \"documentation\":\"

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

\",\ + \"documentation\":\"

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

\",\ \"location\":\"uri\",\ \"locationName\":\"EndpointName\"\ },\ @@ -275,13 +309,13 @@ - (NSString *)definitionString { },\ \"Accept\":{\ \"shape\":\"Header\",\ - \"documentation\":\"

The desired MIME type of the inference in the response.

\",\ + \"documentation\":\"

The desired MIME type of the inference response from the model container.

\",\ \"location\":\"header\",\ \"locationName\":\"Accept\"\ },\ \"CustomAttributes\":{\ \"shape\":\"CustomAttributesHeader\",\ - \"documentation\":\"

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

\",\ + \"documentation\":\"

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

\",\ \"location\":\"header\",\ \"locationName\":\"X-Amzn-SageMaker-Custom-Attributes\"\ },\ @@ -314,6 +348,12 @@ - (NSString *)definitionString { \"documentation\":\"

An optional JMESPath expression used to override the EnableExplanations parameter of the ClarifyExplainerConfig API. See the EnableExplanations section in the developer guide for more information.

\",\ \"location\":\"header\",\ \"locationName\":\"X-Amzn-SageMaker-Enable-Explanations\"\ + },\ + \"InferenceComponentName\":{\ + \"shape\":\"InferenceComponentHeader\",\ + \"documentation\":\"

If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke.

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Inference-Component\"\ }\ },\ \"payload\":\"Body\"\ @@ -328,7 +368,7 @@ - (NSString *)definitionString { },\ \"ContentType\":{\ \"shape\":\"Header\",\ - \"documentation\":\"

The MIME type of the inference returned in the response body.

\",\ + \"documentation\":\"

The MIME type of the inference returned from the model container.

\",\ \"location\":\"header\",\ \"locationName\":\"Content-Type\"\ },\ @@ -347,6 +387,94 @@ - (NSString *)definitionString { },\ \"payload\":\"Body\"\ },\ + \"InvokeEndpointWithResponseStreamInput\":{\ + \"type\":\"structure\",\ + \"required\":[\ + \"EndpointName\",\ + \"Body\"\ + ],\ + \"members\":{\ + \"EndpointName\":{\ + \"shape\":\"EndpointName\",\ + \"documentation\":\"

The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

\",\ + \"location\":\"uri\",\ + \"locationName\":\"EndpointName\"\ + },\ + \"Body\":{\ + \"shape\":\"BodyBlob\",\ + \"documentation\":\"

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

\"\ + },\ + \"ContentType\":{\ + \"shape\":\"Header\",\ + \"documentation\":\"

The MIME type of the input data in the request body.

\",\ + \"location\":\"header\",\ + \"locationName\":\"Content-Type\"\ + },\ + \"Accept\":{\ + \"shape\":\"Header\",\ + \"documentation\":\"

The desired MIME type of the inference response from the model container.

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Accept\"\ + },\ + \"CustomAttributes\":{\ + \"shape\":\"CustomAttributesHeader\",\ + \"documentation\":\"

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

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Custom-Attributes\"\ + },\ + \"TargetVariant\":{\ + \"shape\":\"TargetVariantHeader\",\ + \"documentation\":\"

Specify 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

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Target-Variant\"\ + },\ + \"TargetContainerHostname\":{\ + \"shape\":\"TargetContainerHostnameHeader\",\ + \"documentation\":\"

If the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke.

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Target-Container-Hostname\"\ + },\ + \"InferenceId\":{\ + \"shape\":\"InferenceId\",\ + \"documentation\":\"

An identifier that you assign to your request.

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Inference-Id\"\ + },\ + \"InferenceComponentName\":{\ + \"shape\":\"InferenceComponentHeader\",\ + \"documentation\":\"

If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke for a streaming response.

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Inference-Component\"\ + }\ + },\ + \"payload\":\"Body\"\ + },\ + \"InvokeEndpointWithResponseStreamOutput\":{\ + \"type\":\"structure\",\ + \"required\":[\"Body\"],\ + \"members\":{\ + \"Body\":{\"shape\":\"ResponseStream\"},\ + \"ContentType\":{\ + \"shape\":\"Header\",\ + \"documentation\":\"

The MIME type of the inference returned from the model container.

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Content-Type\"\ + },\ + \"InvokedProductionVariant\":{\ + \"shape\":\"Header\",\ + \"documentation\":\"

Identifies the production variant that was invoked.

\",\ + \"location\":\"header\",\ + \"locationName\":\"x-Amzn-Invoked-Production-Variant\"\ + },\ + \"CustomAttributes\":{\ + \"shape\":\"CustomAttributesHeader\",\ + \"documentation\":\"

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.

\",\ + \"location\":\"header\",\ + \"locationName\":\"X-Amzn-SageMaker-Custom-Attributes\"\ + }\ + },\ + \"payload\":\"Body\"\ + },\ \"LogStreamArn\":{\"type\":\"string\"},\ \"Message\":{\ \"type\":\"string\",\ @@ -383,11 +511,59 @@ - (NSString *)definitionString { \"exception\":true,\ \"synthetic\":true\ },\ + \"ModelStreamError\":{\ + \"type\":\"structure\",\ + \"members\":{\ + \"Message\":{\"shape\":\"Message\"},\ + \"ErrorCode\":{\ + \"shape\":\"ErrorCode\",\ + \"documentation\":\"

This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

\"\ + }\ + },\ + \"documentation\":\"

An error occurred while streaming the response body. This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

\",\ + \"exception\":true,\ + \"synthetic\":true\ + },\ + \"PartBlob\":{\ + \"type\":\"blob\",\ + \"sensitive\":true\ + },\ + \"PayloadPart\":{\ + \"type\":\"structure\",\ + \"members\":{\ + \"Bytes\":{\ + \"shape\":\"PartBlob\",\ + \"documentation\":\"

A blob that contains part of the response for your streaming inference request.

\",\ + \"eventpayload\":true\ + }\ + },\ + \"documentation\":\"

A wrapper for pieces of the payload that's returned in response to a streaming inference request. A streaming inference response consists of one or more payload parts.

\",\ + \"event\":true\ + },\ \"RequestTTLSecondsHeader\":{\ \"type\":\"integer\",\ \"max\":21600,\ \"min\":60\ },\ + \"ResponseStream\":{\ + \"type\":\"structure\",\ + \"members\":{\ + \"PayloadPart\":{\ + \"shape\":\"PayloadPart\",\ + \"documentation\":\"

A wrapper for pieces of the payload that's returned in response to a streaming inference request. A streaming inference response consists of one or more payload parts.

\"\ + },\ + \"ModelStreamError\":{\ + \"shape\":\"ModelStreamError\",\ + \"documentation\":\"

An error occurred while streaming the response body. This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

\"\ + },\ + \"InternalStreamFailure\":{\ + \"shape\":\"InternalStreamFailure\",\ + \"documentation\":\"

The stream processing failed because of an unknown error, exception or failure. Try your request again.

\"\ + }\ + },\ + \"documentation\":\"

A stream of payload parts. Each part contains a portion of the response for a streaming inference request.

\",\ + \"eventstream\":true\ + },\ \"ServiceUnavailable\":{\ \"type\":\"structure\",\ \"members\":{\ diff --git a/AWSSageMakerRuntime/AWSSageMakerRuntimeService.h b/AWSSageMakerRuntime/AWSSageMakerRuntimeService.h index 4683ac1cd0a..274d1747aca 100644 --- a/AWSSageMakerRuntime/AWSSageMakerRuntimeService.h +++ b/AWSSageMakerRuntime/AWSSageMakerRuntimeService.h @@ -200,7 +200,7 @@ FOUNDATION_EXPORT NSString *const AWSSageMakerRuntimeSDKVersion; - (void)invokeEndpoint:(AWSSageMakerRuntimeInvokeEndpointInput *)request completionHandler:(void (^ _Nullable)(AWSSageMakerRuntimeInvokeEndpointOutput * _Nullable response, NSError * _Nullable error))completionHandler; /** -

After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.

Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointAsync are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

+

After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.

Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointAsync are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

@param request A container for the necessary parameters to execute the InvokeEndpointAsync service method. @@ -212,7 +212,7 @@ FOUNDATION_EXPORT NSString *const AWSSageMakerRuntimeSDKVersion; - (AWSTask *)invokeEndpointAsync:(AWSSageMakerRuntimeInvokeEndpointAsyncInput *)request; /** -

After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.

Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointAsync are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

+

After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.

Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointAsync are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

@param request A container for the necessary parameters to execute the InvokeEndpointAsync service method. @param completionHandler The completion handler to call when the load request is complete. @@ -224,6 +224,31 @@ FOUNDATION_EXPORT NSString *const AWSSageMakerRuntimeSDKVersion; */ - (void)invokeEndpointAsync:(AWSSageMakerRuntimeInvokeEndpointAsyncInput *)request completionHandler:(void (^ _Nullable)(AWSSageMakerRuntimeInvokeEndpointAsyncOutput * _Nullable response, NSError * _Nullable error))completionHandler; +/** +

Invokes a model at the specified endpoint to return the inference response as a stream. The inference stream provides the response payload incrementally as a series of parts. Before you can get an inference stream, you must have access to a model that's deployed using Amazon SageMaker hosting services, and the container for that model must support inference streaming.

For more information that can help you use this API, see the following sections in the Amazon SageMaker Developer Guide:

Before you can use this operation, your IAM permissions must allow the sagemaker:InvokeEndpoint action. For more information about Amazon SageMaker actions for IAM policies, see Actions, resources, and condition keys for Amazon SageMaker in the IAM Service Authorization Reference.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointWithResponseStream are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

+ + @param request A container for the necessary parameters to execute the InvokeEndpointWithResponseStream service method. + + @return An instance of `AWSTask`. On successful execution, `task.result` will contain an instance of `AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput`. On failed execution, `task.error` may contain an `NSError` with `AWSSageMakerRuntimeErrorDomain` domain and the following error code: `AWSSageMakerRuntimeErrorInternalFailure`, `AWSSageMakerRuntimeErrorServiceUnavailable`, `AWSSageMakerRuntimeErrorValidation`, `AWSSageMakerRuntimeErrorModel`, `AWSSageMakerRuntimeErrorModelStream`, `AWSSageMakerRuntimeErrorInternalStreamFailure`. + + @see AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput + @see AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput + */ +- (AWSTask *)invokeEndpointWithResponseStream:(AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput *)request; + +/** +

Invokes a model at the specified endpoint to return the inference response as a stream. The inference stream provides the response payload incrementally as a series of parts. Before you can get an inference stream, you must have access to a model that's deployed using Amazon SageMaker hosting services, and the container for that model must support inference streaming.

For more information that can help you use this API, see the following sections in the Amazon SageMaker Developer Guide:

Before you can use this operation, your IAM permissions must allow the sagemaker:InvokeEndpoint action. For more information about Amazon SageMaker actions for IAM policies, see Actions, resources, and condition keys for Amazon SageMaker in the IAM Service Authorization Reference.

Amazon SageMaker strips all POST headers except those supported by the API. Amazon SageMaker might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointWithResponseStream are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

+ + @param request A container for the necessary parameters to execute the InvokeEndpointWithResponseStream service method. + @param completionHandler The completion handler to call when the load request is complete. + `response` - A response object, or `nil` if the request failed. + `error` - An error object that indicates why the request failed, or `nil` if the request was successful. On failed execution, `error` may contain an `NSError` with `AWSSageMakerRuntimeErrorDomain` domain and the following error code: `AWSSageMakerRuntimeErrorInternalFailure`, `AWSSageMakerRuntimeErrorServiceUnavailable`, `AWSSageMakerRuntimeErrorValidation`, `AWSSageMakerRuntimeErrorModel`, `AWSSageMakerRuntimeErrorModelStream`, `AWSSageMakerRuntimeErrorInternalStreamFailure`. + + @see AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput + @see AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput + */ +- (void)invokeEndpointWithResponseStream:(AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput *)request completionHandler:(void (^ _Nullable)(AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput * _Nullable response, NSError * _Nullable error))completionHandler; + @end NS_ASSUME_NONNULL_END diff --git a/AWSSageMakerRuntime/AWSSageMakerRuntimeService.m b/AWSSageMakerRuntime/AWSSageMakerRuntimeService.m index d01c1e413ad..33ed7b5f8cb 100644 --- a/AWSSageMakerRuntime/AWSSageMakerRuntimeService.m +++ b/AWSSageMakerRuntime/AWSSageMakerRuntimeService.m @@ -41,8 +41,10 @@ + (void)initialize { errorCodeDictionary = @{ @"InternalDependencyException" : @(AWSSageMakerRuntimeErrorInternalDependency), @"InternalFailure" : @(AWSSageMakerRuntimeErrorInternalFailure), + @"InternalStreamFailure" : @(AWSSageMakerRuntimeErrorInternalStreamFailure), @"ModelError" : @(AWSSageMakerRuntimeErrorModel), @"ModelNotReadyException" : @(AWSSageMakerRuntimeErrorModelNotReady), + @"ModelStreamError" : @(AWSSageMakerRuntimeErrorModelStream), @"ServiceUnavailable" : @(AWSSageMakerRuntimeErrorServiceUnavailable), @"ValidationError" : @(AWSSageMakerRuntimeErrorValidation), }; @@ -327,6 +329,29 @@ - (void)invokeEndpointAsync:(AWSSageMakerRuntimeInvokeEndpointAsyncInput *)reque }]; } +- (AWSTask *)invokeEndpointWithResponseStream:(AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput *)request { + return [self invokeRequest:request + HTTPMethod:AWSHTTPMethodPOST + URLString:@"/endpoints/{EndpointName}/invocations-response-stream" + targetPrefix:@"" + operationName:@"InvokeEndpointWithResponseStream" + outputClass:[AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput class]]; +} + +- (void)invokeEndpointWithResponseStream:(AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput *)request + completionHandler:(void (^)(AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput *response, NSError *error))completionHandler { + [[self invokeEndpointWithResponseStream:request] continueWithBlock:^id _Nullable(AWSTask * _Nonnull task) { + AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput *result = task.result; + NSError *error = task.error; + + if (completionHandler) { + completionHandler(result, error); + } + + return nil; + }]; +} + #pragma mark - @end diff --git a/AWSSageMakerRuntimeUnitTests/AWSGeneralSageMakerRuntimeTests.m b/AWSSageMakerRuntimeUnitTests/AWSGeneralSageMakerRuntimeTests.m index ff5f18eb27f..ecc41b130df 100644 --- a/AWSSageMakerRuntimeUnitTests/AWSGeneralSageMakerRuntimeTests.m +++ b/AWSSageMakerRuntimeUnitTests/AWSGeneralSageMakerRuntimeTests.m @@ -153,4 +153,52 @@ - (void)testInvokeEndpointAsyncCompletionHandler { [AWSSageMakerRuntime removeSageMakerRuntimeForKey:key]; } +- (void)testInvokeEndpointWithResponseStream { + NSString *key = @"testInvokeEndpointWithResponseStream"; + AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; + [AWSSageMakerRuntime registerSageMakerRuntimeWithConfiguration:configuration forKey:key]; + + AWSSageMakerRuntime *awsClient = [AWSSageMakerRuntime SageMakerRuntimeForKey:key]; + XCTAssertNotNil(awsClient); + XCTAssertNotNil(mockNetworking); + [awsClient setValue:mockNetworking forKey:@"networking"]; + [[[[AWSSageMakerRuntime SageMakerRuntimeForKey:key] invokeEndpointWithResponseStream:[AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput new]] continueWithBlock:^id(AWSTask *task) { + XCTAssertNotNil(task.error); + XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); + XCTAssertEqual(8848, task.error.code); + XCTAssertNil(task.result); + return nil; + }] waitUntilFinished]; + + OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); + + [AWSSageMakerRuntime removeSageMakerRuntimeForKey:key]; +} + +- (void)testInvokeEndpointWithResponseStreamCompletionHandler { + NSString *key = @"testInvokeEndpointWithResponseStream"; + AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; + [AWSSageMakerRuntime registerSageMakerRuntimeWithConfiguration:configuration forKey:key]; + + AWSSageMakerRuntime *awsClient = [AWSSageMakerRuntime SageMakerRuntimeForKey:key]; + XCTAssertNotNil(awsClient); + XCTAssertNotNil(mockNetworking); + [awsClient setValue:mockNetworking forKey:@"networking"]; + + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + + [[AWSSageMakerRuntime SageMakerRuntimeForKey:key] invokeEndpointWithResponseStream:[AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput new] completionHandler:^(AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput* _Nullable response, NSError * _Nullable error) { + XCTAssertNotNil(error); + XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); + XCTAssertEqual(8848, error.code); + XCTAssertNil(response); + dispatch_semaphore_signal(semaphore); + }]; + + dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); + OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); + + [AWSSageMakerRuntime removeSageMakerRuntimeForKey:key]; +} + @end diff --git a/AWSSageMakerRuntimeUnitTests/AWSSageMakerRuntimeNSSecureCodingTests.m b/AWSSageMakerRuntimeUnitTests/AWSSageMakerRuntimeNSSecureCodingTests.m index 1c2c932d136..95cb8ab1d83 100644 --- a/AWSSageMakerRuntimeUnitTests/AWSSageMakerRuntimeNSSecureCodingTests.m +++ b/AWSSageMakerRuntimeUnitTests/AWSSageMakerRuntimeNSSecureCodingTests.m @@ -23,6 +23,10 @@ - (void) test_AWSSageMakerRuntimeInvokeEndpointAsyncInput API_AVAILABLE(ios(11)) - (void) test_AWSSageMakerRuntimeInvokeEndpointAsyncOutput API_AVAILABLE(ios(11)); - (void) test_AWSSageMakerRuntimeInvokeEndpointInput API_AVAILABLE(ios(11)); - (void) test_AWSSageMakerRuntimeInvokeEndpointOutput API_AVAILABLE(ios(11)); +- (void) test_AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput API_AVAILABLE(ios(11)); +- (void) test_AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput API_AVAILABLE(ios(11)); +- (void) test_AWSSageMakerRuntimePayloadPart API_AVAILABLE(ios(11)); +- (void) test_AWSSageMakerRuntimeResponseStream API_AVAILABLE(ios(11)); @end @@ -44,5 +48,21 @@ - (void) test_AWSSageMakerRuntimeInvokeEndpointOutput { [self validateSecureCodingForClass:[AWSSageMakerRuntimeInvokeEndpointOutput class]]; } +- (void) test_AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput { + [self validateSecureCodingForClass:[AWSSageMakerRuntimeInvokeEndpointWithResponseStreamInput class]]; +} + +- (void) test_AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput { + [self validateSecureCodingForClass:[AWSSageMakerRuntimeInvokeEndpointWithResponseStreamOutput class]]; +} + +- (void) test_AWSSageMakerRuntimePayloadPart { + [self validateSecureCodingForClass:[AWSSageMakerRuntimePayloadPart class]]; +} + +- (void) test_AWSSageMakerRuntimeResponseStream { + [self validateSecureCodingForClass:[AWSSageMakerRuntimeResponseStream class]]; +} + @end