5353from sagemaker .model_card .schema_constraints import ModelApprovalStatusEnum
5454from sagemaker .session import Session
5555from sagemaker .model_metrics import ModelMetrics
56- from sagemaker .deprecations import removed_kwargs
5756from sagemaker .drift_check_baselines import DriftCheckBaselines
5857from sagemaker .explainer import ExplainerConfig
5958from sagemaker .metadata_properties import MetadataProperties
@@ -1386,6 +1385,7 @@ def deploy(
13861385 routing_config : Optional [Dict [str , Any ]] = None ,
13871386 model_reference_arn : Optional [str ] = None ,
13881387 inference_ami_version : Optional [str ] = None ,
1388+ update_endpoint : Optional [bool ] = False ,
13891389 ** kwargs ,
13901390 ):
13911391 """Deploy this ``Model`` to an ``Endpoint`` and optionally return a ``Predictor``.
@@ -1497,6 +1497,10 @@ def deploy(
14971497 inference_ami_version (Optional [str]): Specifies an option from a collection of preconfigured
14981498 Amazon Machine Image (AMI) images. For a full list of options, see:
14991499 https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProductionVariant.html
1500+ update_endpoint (Optional[bool]): Flag to update the model in an existing Amazon SageMaker endpoint.
1501+ If True, this will deploy a new EndpointConfig to an already existing endpoint and delete resources
1502+ corresponding to the previous EndpointConfig. Default: False
1503+ Note: Currently this is supported for single model endpoints
15001504 Raises:
15011505 ValueError: If arguments combination check failed in these circumstances:
15021506 - If no role is specified or
@@ -1512,8 +1516,6 @@ def deploy(
15121516 """
15131517 self .accept_eula = accept_eula
15141518
1515- removed_kwargs ("update_endpoint" , kwargs )
1516-
15171519 self ._init_sagemaker_session_if_does_not_exist (instance_type )
15181520 # Depending on the instance type, a local session (or) a session is initialized.
15191521 self .role = resolve_value_from_config (
@@ -1628,6 +1630,8 @@ def deploy(
16281630
16291631 # Support multiple models on same endpoint
16301632 if endpoint_type == EndpointType .INFERENCE_COMPONENT_BASED :
1633+ if update_endpoint :
1634+ raise ValueError ("Currently update_endpoint is supported for single model endpoints" )
16311635 if endpoint_name :
16321636 self .endpoint_name = endpoint_name
16331637 else :
@@ -1783,17 +1787,38 @@ def deploy(
17831787 if is_explainer_enabled :
17841788 explainer_config_dict = explainer_config ._to_request_dict ()
17851789
1786- self .sagemaker_session .endpoint_from_production_variants (
1787- name = self .endpoint_name ,
1788- production_variants = [production_variant ],
1789- tags = tags ,
1790- kms_key = kms_key ,
1791- wait = wait ,
1792- data_capture_config_dict = data_capture_config_dict ,
1793- explainer_config_dict = explainer_config_dict ,
1794- async_inference_config_dict = async_inference_config_dict ,
1795- live_logging = endpoint_logging ,
1796- )
1790+ if update_endpoint :
1791+ endpoint_config_name = self .sagemaker_session .create_endpoint_config (
1792+ name = self .name ,
1793+ model_name = self .name ,
1794+ initial_instance_count = initial_instance_count ,
1795+ instance_type = instance_type ,
1796+ accelerator_type = accelerator_type ,
1797+ tags = tags ,
1798+ kms_key = kms_key ,
1799+ data_capture_config_dict = data_capture_config_dict ,
1800+ volume_size = volume_size ,
1801+ model_data_download_timeout = model_data_download_timeout ,
1802+ container_startup_health_check_timeout = container_startup_health_check_timeout ,
1803+ explainer_config_dict = explainer_config_dict ,
1804+ async_inference_config_dict = async_inference_config_dict ,
1805+ serverless_inference_config = serverless_inference_config_dict ,
1806+ routing_config = routing_config ,
1807+ inference_ami_version = inference_ami_version ,
1808+ )
1809+ self .sagemaker_session .update_endpoint (self .endpoint_name , endpoint_config_name )
1810+ else :
1811+ self .sagemaker_session .endpoint_from_production_variants (
1812+ name = self .endpoint_name ,
1813+ production_variants = [production_variant ],
1814+ tags = tags ,
1815+ kms_key = kms_key ,
1816+ wait = wait ,
1817+ data_capture_config_dict = data_capture_config_dict ,
1818+ explainer_config_dict = explainer_config_dict ,
1819+ async_inference_config_dict = async_inference_config_dict ,
1820+ live_logging = endpoint_logging ,
1821+ )
17971822
17981823 if self .predictor_cls :
17991824 predictor = self .predictor_cls (self .endpoint_name , self .sagemaker_session )
0 commit comments