From 5f38d6b43c6de6171a4d0fab2d389f5115b9e1bd Mon Sep 17 00:00:00 2001 From: awstools Date: Mon, 9 Sep 2024 18:17:41 +0000 Subject: [PATCH] feat(client-sagemaker-runtime): AWS SageMaker Runtime feature: Add sticky routing to support stateful inference models. --- .../src/commands/InvokeEndpointCommand.ts | 3 + ...InvokeEndpointWithResponseStreamCommand.ts | 1 + .../src/models/models_0.ts | 49 ++++++++++++++++ .../src/protocols/Aws_restJson1.ts | 10 ++++ .../aws-models/sagemaker-runtime.json | 58 +++++++++++++++++++ 5 files changed, 121 insertions(+) diff --git a/clients/client-sagemaker-runtime/src/commands/InvokeEndpointCommand.ts b/clients/client-sagemaker-runtime/src/commands/InvokeEndpointCommand.ts index d627288c53443..8a0e54062def8 100644 --- a/clients/client-sagemaker-runtime/src/commands/InvokeEndpointCommand.ts +++ b/clients/client-sagemaker-runtime/src/commands/InvokeEndpointCommand.ts @@ -85,6 +85,7 @@ export interface InvokeEndpointCommandOutput extends InvokeEndpointCommandOutput * InferenceId: "STRING_VALUE", * EnableExplanations: "STRING_VALUE", * InferenceComponentName: "STRING_VALUE", + * SessionId: "STRING_VALUE", * }; * const command = new InvokeEndpointCommand(input); * const response = await client.send(command); @@ -93,6 +94,8 @@ export interface InvokeEndpointCommandOutput extends InvokeEndpointCommandOutput * // ContentType: "STRING_VALUE", * // InvokedProductionVariant: "STRING_VALUE", * // CustomAttributes: "STRING_VALUE", + * // NewSessionId: "STRING_VALUE", + * // ClosedSessionId: "STRING_VALUE", * // }; * * ``` diff --git a/clients/client-sagemaker-runtime/src/commands/InvokeEndpointWithResponseStreamCommand.ts b/clients/client-sagemaker-runtime/src/commands/InvokeEndpointWithResponseStreamCommand.ts index cf2a9aa6d10dc..6c5c6d8b97b53 100644 --- a/clients/client-sagemaker-runtime/src/commands/InvokeEndpointWithResponseStreamCommand.ts +++ b/clients/client-sagemaker-runtime/src/commands/InvokeEndpointWithResponseStreamCommand.ts @@ -86,6 +86,7 @@ export interface InvokeEndpointWithResponseStreamCommandOutput * TargetContainerHostname: "STRING_VALUE", * InferenceId: "STRING_VALUE", * InferenceComponentName: "STRING_VALUE", + * SessionId: "STRING_VALUE", * }; * const command = new InvokeEndpointWithResponseStreamCommand(input); * const response = await client.send(command); diff --git a/clients/client-sagemaker-runtime/src/models/models_0.ts b/clients/client-sagemaker-runtime/src/models/models_0.ts index 509d9e3fda919..32ac554fb1cac 100644 --- a/clients/client-sagemaker-runtime/src/models/models_0.ts +++ b/clients/client-sagemaker-runtime/src/models/models_0.ts @@ -146,6 +146,28 @@ export interface InvokeEndpointInput { * @public */ InferenceComponentName?: string; + + /** + *

Creates a stateful session or identifies an existing one. You can do one of the + * following:

+ * + *

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.

+ * @public + */ + SessionId?: string; } /** @@ -195,6 +217,19 @@ export interface InvokeEndpointOutput { * @public */ CustomAttributes?: string; + + /** + *

If you created a stateful session with your request, the ID and expiration time that + * the model assigns to that session.

+ * @public + */ + NewSessionId?: string; + + /** + *

If you closed a stateful session with your request, the ID of that session.

+ * @public + */ + ClosedSessionId?: string; } /** @@ -508,6 +543,20 @@ export interface InvokeEndpointWithResponseStreamInput { * @public */ InferenceComponentName?: string; + + /** + *

The 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 the + * InvokeEndpoint + * action. In your request, you + * specify NEW_SESSION for the SessionId request parameter. The + * response to that request provides the session ID for the NewSessionId + * response parameter.

+ * @public + */ + SessionId?: string; } /** diff --git a/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts b/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts index cefe9e07b98d9..4b044e9d0676b 100644 --- a/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts @@ -63,6 +63,7 @@ export const se_InvokeEndpointCommand = async ( [_xasii]: input[_II]!, [_xasee]: input[_EE]!, [_xasic]: input[_ICN]!, + [_xassi]: input[_SI]!, }); b.bp("/endpoints/{EndpointName}/invocations"); b.p("EndpointName", () => input.EndpointName!, "{EndpointName}", false); @@ -114,6 +115,7 @@ export const se_InvokeEndpointWithResponseStreamCommand = async ( [_xastch]: input[_TCH]!, [_xasii]: input[_II]!, [_xasic]: input[_ICN]!, + [_xassi]: input[_SI]!, }); b.bp("/endpoints/{EndpointName}/invocations-response-stream"); b.p("EndpointName", () => input.EndpointName!, "{EndpointName}", false); @@ -140,6 +142,8 @@ export const de_InvokeEndpointCommand = async ( [_CT]: [, output.headers[_ct]], [_IPV]: [, output.headers[_xaipv]], [_CA]: [, output.headers[_xasca]], + [_NSI]: [, output.headers[_xasnsi]], + [_CSI]: [, output.headers[_xascsi]], }); const data: any = await collectBody(output.body, context); contents.Body = data; @@ -450,6 +454,7 @@ const isSerializableHeaderValue = (value: any): boolean => const _A = "Accept"; const _CA = "CustomAttributes"; +const _CSI = "ClosedSessionId"; const _CT = "ContentType"; const _EE = "EnableExplanations"; const _FL = "FailureLocation"; @@ -458,8 +463,10 @@ const _II = "InferenceId"; const _IL = "InputLocation"; const _IPV = "InvokedProductionVariant"; const _ITS = "InvocationTimeoutSeconds"; +const _NSI = "NewSessionId"; const _OL = "OutputLocation"; const _RTTLS = "RequestTTLSeconds"; +const _SI = "SessionId"; const _TCH = "TargetContainerHostname"; const _TM = "TargetModel"; const _TV = "TargetVariant"; @@ -468,6 +475,7 @@ const _ct = "content-type"; const _xaipv = "x-amzn-invoked-production-variant"; const _xasa = "x-amzn-sagemaker-accept"; const _xasca = "x-amzn-sagemaker-custom-attributes"; +const _xascsi = "x-amzn-sagemaker-closed-session-id"; const _xasct = "x-amzn-sagemaker-content-type"; const _xasee = "x-amzn-sagemaker-enable-explanations"; const _xasf = "x-amzn-sagemaker-failurelocation"; @@ -475,8 +483,10 @@ const _xasi = "x-amzn-sagemaker-inputlocation"; const _xasi_ = "x-amzn-sagemaker-invocationtimeoutseconds"; const _xasic = "x-amzn-sagemaker-inference-component"; const _xasii = "x-amzn-sagemaker-inference-id"; +const _xasnsi = "x-amzn-sagemaker-new-session-id"; const _xaso = "x-amzn-sagemaker-outputlocation"; const _xasr = "x-amzn-sagemaker-requestttlseconds"; +const _xassi = "x-amzn-sagemaker-session-id"; const _xastch = "x-amzn-sagemaker-target-container-hostname"; const _xastm = "x-amzn-sagemaker-target-model"; const _xastv = "x-amzn-sagemaker-target-variant"; diff --git a/codegen/sdk-codegen/aws-models/sagemaker-runtime.json b/codegen/sdk-codegen/aws-models/sagemaker-runtime.json index b3d910354a5f8..8333f192b2429 100644 --- a/codegen/sdk-codegen/aws-models/sagemaker-runtime.json +++ b/codegen/sdk-codegen/aws-models/sagemaker-runtime.json @@ -1449,6 +1449,13 @@ "smithy.api#documentation": "

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

", "smithy.api#httpHeader": "X-Amzn-SageMaker-Inference-Component" } + }, + "SessionId": { + "target": "com.amazonaws.sagemakerruntime#SessionIdOrNewSessionConstantHeader", + "traits": { + "smithy.api#documentation": "

Creates a stateful session or identifies an existing one. You can do one of the\n following:

\n \n

With a stateful session, you can send multiple requests to a stateful model. When you\n create a session with a stateful model, the model must create the session ID and set the\n expiration time. The model must also provide that information in the response to your\n request. You can get the ID and timestamp from the NewSessionId response\n parameter. For any subsequent request where you specify that session ID, SageMaker routes the request to the same instance that supports the session.

", + "smithy.api#httpHeader": "X-Amzn-SageMaker-Session-Id" + } } }, "traits": { @@ -1487,6 +1494,20 @@ "smithy.api#documentation": "

Provides additional information in the response about the inference returned by a\n model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is\n forwarded verbatim. You could use this value, for example, to return an ID received in\n the CustomAttributes header of a request or other metadata that a service\n endpoint was programmed to produce. The value must consist of no more than 1024 visible\n US-ASCII characters as specified in Section 3.3.6. Field Value\n Components of the Hypertext Transfer Protocol (HTTP/1.1). If the customer\n wants the custom attribute returned, the model must set the custom attribute to be\n included on the way back.

\n

The code in your model is responsible for setting or updating any custom attributes in\n the response. If your code does not set this value in the response, an empty value is\n returned. For example, if a custom attribute represents the trace ID, your model can\n prepend the custom attribute with Trace ID: in your post-processing\n function.

\n

This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker\n Python SDK.

", "smithy.api#httpHeader": "X-Amzn-SageMaker-Custom-Attributes" } + }, + "NewSessionId": { + "target": "com.amazonaws.sagemakerruntime#NewSessionResponseHeader", + "traits": { + "smithy.api#documentation": "

If you created a stateful session with your request, the ID and expiration time that\n the model assigns to that session.

", + "smithy.api#httpHeader": "X-Amzn-SageMaker-New-Session-Id" + } + }, + "ClosedSessionId": { + "target": "com.amazonaws.sagemakerruntime#SessionIdHeader", + "traits": { + "smithy.api#documentation": "

If you closed a stateful session with your request, the ID of that session.

", + "smithy.api#httpHeader": "X-Amzn-SageMaker-Closed-Session-Id" + } } }, "traits": { @@ -1598,6 +1619,13 @@ "smithy.api#documentation": "

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

", "smithy.api#httpHeader": "X-Amzn-SageMaker-Inference-Component" } + }, + "SessionId": { + "target": "com.amazonaws.sagemakerruntime#SessionIdHeader", + "traits": { + "smithy.api#documentation": "

The ID of a stateful session to handle your request.

\n

You can't create a stateful session by using the\n InvokeEndpointWithResponseStream action. Instead, you can create one by\n using the \n InvokeEndpoint\n action. In your request, you\n specify NEW_SESSION for the SessionId request parameter. The\n response to that request provides the session ID for the NewSessionId\n response parameter.

", + "smithy.api#httpHeader": "X-Amzn-SageMaker-Session-Id" + } } }, "traits": { @@ -1718,6 +1746,16 @@ "smithy.api#error": "client" } }, + "com.amazonaws.sagemakerruntime#NewSessionResponseHeader": { + "type": "string", + "traits": { + "smithy.api#length": { + "min": 0, + "max": 256 + }, + "smithy.api#pattern": "^[a-zA-Z0-9](-*[a-zA-Z0-9])*;\\sExpires=[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" + } + }, "com.amazonaws.sagemakerruntime#PartBlob": { "type": "blob", "traits": { @@ -1788,6 +1826,26 @@ "smithy.api#httpError": 503 } }, + "com.amazonaws.sagemakerruntime#SessionIdHeader": { + "type": "string", + "traits": { + "smithy.api#length": { + "min": 0, + "max": 256 + }, + "smithy.api#pattern": "^[a-zA-Z0-9](-*[a-zA-Z0-9])*$" + } + }, + "com.amazonaws.sagemakerruntime#SessionIdOrNewSessionConstantHeader": { + "type": "string", + "traits": { + "smithy.api#length": { + "min": 0, + "max": 256 + }, + "smithy.api#pattern": "^(NEW_SESSION)$|^[a-zA-Z0-9](-*[a-zA-Z0-9])*$" + } + }, "com.amazonaws.sagemakerruntime#StatusCode": { "type": "integer" },