@@ -77,10 +77,9 @@ def sagemaker_xgboost_wf(
7777from flytekitplugins .awssagemaker_inference import create_sagemaker_deployment
7878
7979REGION = "us-east-2"
80- MODEL_NAME = "xgboost"
81- ENDPOINT_CONFIG_NAME = "xgboost-endpoint-config"
82- ENDPOINT_NAME = "xgboost-endpoint"
8380S3_OUTPUT_PATH = "s3://sagemaker-agent-xgboost/inference-output/output"
81+ NEW_DEPLOYMENT_NAME = "xgboost-fastapi-{idempotence_token}"
82+ EXISTING_DEPLOYMENT_NAME = "xgboost-fastapi-{inputs.idempotence_token}"
8483
8584sagemaker_image = ImageSpec (
8685 name = "sagemaker-xgboost" ,
@@ -94,7 +93,7 @@ def sagemaker_xgboost_wf(
9493 name = "xgboost" ,
9594 model_input_types = kwtypes (model_path = str , execution_role_arn = str ),
9695 model_config = {
97- "ModelName" : MODEL_NAME ,
96+ "ModelName" : NEW_DEPLOYMENT_NAME ,
9897 "PrimaryContainer" : {
9998 "Image" : "{images.primary_container_image}" ,
10099 "ModelDataUrl" : "{inputs.model_path}" ,
@@ -103,20 +102,20 @@ def sagemaker_xgboost_wf(
103102 },
104103 endpoint_config_input_types = kwtypes (instance_type = str ),
105104 endpoint_config_config = {
106- "EndpointConfigName" : ENDPOINT_CONFIG_NAME ,
105+ "EndpointConfigName" : NEW_DEPLOYMENT_NAME ,
107106 "ProductionVariants" : [
108107 {
109108 "VariantName" : "variant-name-1" ,
110- "ModelName" : MODEL_NAME ,
109+ "ModelName" : EXISTING_DEPLOYMENT_NAME ,
111110 "InitialInstanceCount" : 1 ,
112111 "InstanceType" : "{inputs.instance_type}" ,
113112 },
114113 ],
115114 "AsyncInferenceConfig" : {"OutputConfig" : {"S3OutputPath" : S3_OUTPUT_PATH }},
116115 },
117116 endpoint_config = {
118- "EndpointName" : ENDPOINT_NAME ,
119- "EndpointConfigName" : ENDPOINT_CONFIG_NAME ,
117+ "EndpointName" : NEW_DEPLOYMENT_NAME ,
118+ "EndpointConfigName" : EXISTING_DEPLOYMENT_NAME ,
120119 },
121120 images = {"primary_container_image" : sagemaker_image },
122121 region = REGION ,
@@ -128,13 +127,21 @@ def sagemaker_xgboost_wf(
128127# and initializing an endpoint. Configurations relevant to these tasks are passed to the
129128# {py:func}`~flytekitplugins.awssagemaker_inference.create_sagemaker_deployment` function.
130129#
130+ # An idempotence token ensures the generation of unique tokens for each configuration, preventing name collisions during updates.
131+ #
132+ # - `idempotence_token` represents the configuration hash.
133+ # - `inputs.idempotence_token` refers to the idempotence token from the previous task.
134+ # The workflow injects idempotence token from the previous task into the current task as an input.
135+ #
131136# `sagemaker_image` should include the inference code, necessary libraries, and an entrypoint for model serving.
132137#
133138# :::{note}
134139# For more detailed instructions on using your custom inference image, refer to the
135140# [Amazon SageMaker documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-inference-code.html).
136141# :::
137142#
143+ # If the plugin attempts to create a deployment that already exists, it will return the existing ARNs instead of raising an error.
144+ #
138145# To receive inference requests, the container built with `sagemaker_image` must have a web server
139146# listening on port 8080 and must accept POST and GET requests to the `/invocations` and `/ping` endpoints, respectively.
140147#
@@ -227,7 +234,7 @@ async def invocations(request: Request):
227234invoke_endpoint = SageMakerInvokeEndpointTask (
228235 name = "sagemaker_invoke_endpoint" ,
229236 config = {
230- "EndpointName" : ENDPOINT_NAME ,
237+ "EndpointName" : "YOUR_ENDPOINT_NAME_HERE" ,
231238 "InputLocation" : "s3://sagemaker-agent-xgboost/inference_input" ,
232239 },
233240 region = REGION ,
@@ -248,9 +255,9 @@ async def invocations(request: Request):
248255@workflow
249256def deployment_deletion_workflow ():
250257 sagemaker_deployment_deletion_wf (
251- endpoint_name = ENDPOINT_NAME ,
252- endpoint_config_name = ENDPOINT_CONFIG_NAME ,
253- model_name = MODEL_NAME ,
258+ endpoint_name = "YOUR_ENDPOINT_NAME_HERE" ,
259+ endpoint_config_name = "YOUR_ENDPOINT_CONFIG_NAME_HERE" ,
260+ model_name = "YOUR_MODEL_NAME_HERE" ,
254261 )
255262
256263
0 commit comments