Skip to content

Commit

Permalink
feat(client-sagemaker-runtime): AWS SageMaker Runtime feature: Add st…
Browse files Browse the repository at this point in the history
…icky routing to support stateful inference models.
  • Loading branch information
awstools committed Sep 9, 2024
1 parent 55553d6 commit 5f38d6b
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -93,6 +94,8 @@ export interface InvokeEndpointCommandOutput extends InvokeEndpointCommandOutput
* // ContentType: "STRING_VALUE",
* // InvokedProductionVariant: "STRING_VALUE",
* // CustomAttributes: "STRING_VALUE",
* // NewSessionId: "STRING_VALUE",
* // ClosedSessionId: "STRING_VALUE",
* // };
*
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
49 changes: 49 additions & 0 deletions clients/client-sagemaker-runtime/src/models/models_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ export interface InvokeEndpointInput {
* @public
*/
InferenceComponentName?: string;

/**
* <p>Creates a stateful session or identifies an existing one. You can do one of the
* following:</p>
* <ul>
* <li>
* <p>Create a stateful session by specifying the value
* <code>NEW_SESSION</code>.</p>
* </li>
* <li>
* <p>Send your request to an existing stateful session by specifying the ID of that
* session.</p>
* </li>
* </ul>
* <p>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 <code>NewSessionId</code> response
* parameter. For any subsequent request where you specify that session ID, SageMaker routes the request to the same instance that supports the session.</p>
* @public
*/
SessionId?: string;
}

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

/**
* <p>If you created a stateful session with your request, the ID and expiration time that
* the model assigns to that session.</p>
* @public
*/
NewSessionId?: string;

/**
* <p>If you closed a stateful session with your request, the ID of that session.</p>
* @public
*/
ClosedSessionId?: string;
}

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

/**
* <p>The ID of a stateful session to handle your request.</p>
* <p>You can't create a stateful session by using the
* <code>InvokeEndpointWithResponseStream</code> action. Instead, you can create one by
* using the <code>
* <a>InvokeEndpoint</a>
* </code> action. In your request, you
* specify <code>NEW_SESSION</code> for the <code>SessionId</code> request parameter. The
* response to that request provides the session ID for the <code>NewSessionId</code>
* response parameter.</p>
* @public
*/
SessionId?: string;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -468,15 +475,18 @@ 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";
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";
58 changes: 58 additions & 0 deletions codegen/sdk-codegen/aws-models/sagemaker-runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,13 @@
"smithy.api#documentation": "<p>If the endpoint hosts one or more inference components, this parameter specifies the\n name of inference component to invoke.</p>",
"smithy.api#httpHeader": "X-Amzn-SageMaker-Inference-Component"
}
},
"SessionId": {
"target": "com.amazonaws.sagemakerruntime#SessionIdOrNewSessionConstantHeader",
"traits": {
"smithy.api#documentation": "<p>Creates a stateful session or identifies an existing one. You can do one of the\n following:</p>\n <ul>\n <li>\n <p>Create a stateful session by specifying the value\n <code>NEW_SESSION</code>.</p>\n </li>\n <li>\n <p>Send your request to an existing stateful session by specifying the ID of that\n session.</p>\n </li>\n </ul>\n <p>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 <code>NewSessionId</code> 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.</p>",
"smithy.api#httpHeader": "X-Amzn-SageMaker-Session-Id"
}
}
},
"traits": {
Expand Down Expand Up @@ -1487,6 +1494,20 @@
"smithy.api#documentation": "<p>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 <code>CustomAttributes</code> 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 <a href=\"https://tools.ietf.org/html/rfc7230#section-3.2.6\">Section 3.3.6. Field Value\n Components</a> 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. </p>\n <p>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 <code>Trace ID:</code> in your post-processing\n function.</p>\n <p>This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker\n Python SDK.</p>",
"smithy.api#httpHeader": "X-Amzn-SageMaker-Custom-Attributes"
}
},
"NewSessionId": {
"target": "com.amazonaws.sagemakerruntime#NewSessionResponseHeader",
"traits": {
"smithy.api#documentation": "<p>If you created a stateful session with your request, the ID and expiration time that\n the model assigns to that session.</p>",
"smithy.api#httpHeader": "X-Amzn-SageMaker-New-Session-Id"
}
},
"ClosedSessionId": {
"target": "com.amazonaws.sagemakerruntime#SessionIdHeader",
"traits": {
"smithy.api#documentation": "<p>If you closed a stateful session with your request, the ID of that session.</p>",
"smithy.api#httpHeader": "X-Amzn-SageMaker-Closed-Session-Id"
}
}
},
"traits": {
Expand Down Expand Up @@ -1598,6 +1619,13 @@
"smithy.api#documentation": "<p>If the endpoint hosts one or more inference components, this parameter specifies the\n name of inference component to invoke for a streaming response.</p>",
"smithy.api#httpHeader": "X-Amzn-SageMaker-Inference-Component"
}
},
"SessionId": {
"target": "com.amazonaws.sagemakerruntime#SessionIdHeader",
"traits": {
"smithy.api#documentation": "<p>The ID of a stateful session to handle your request.</p>\n <p>You can't create a stateful session by using the\n <code>InvokeEndpointWithResponseStream</code> action. Instead, you can create one by\n using the <code>\n <a>InvokeEndpoint</a>\n </code> action. In your request, you\n specify <code>NEW_SESSION</code> for the <code>SessionId</code> request parameter. The\n response to that request provides the session ID for the <code>NewSessionId</code>\n response parameter.</p>",
"smithy.api#httpHeader": "X-Amzn-SageMaker-Session-Id"
}
}
},
"traits": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
},
Expand Down

0 comments on commit 5f38d6b

Please sign in to comment.