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,11 @@ 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]):
1501+ Flag to update the model in an existing Amazon SageMaker endpoint.
1502+ If True, this will deploy a new EndpointConfig to an already existing endpoint
1503+ and delete resources corresponding to the previous EndpointConfig. Default: False
1504+ Note: Currently this is supported for single model endpoints
15001505 Raises:
15011506 ValueError: If arguments combination check failed in these circumstances:
15021507 - If no role is specified or
@@ -1512,8 +1517,6 @@ def deploy(
15121517 """
15131518 self.accept_eula = accept_eula
15141519
1515- removed_kwargs("update_endpoint", kwargs)
1516-
15171520 self._init_sagemaker_session_if_does_not_exist(instance_type)
15181521 # Depending on the instance type, a local session (or) a session is initialized.
15191522 self.role = resolve_value_from_config(
@@ -1628,6 +1631,10 @@ def deploy(
16281631
16291632 # Support multiple models on same endpoint
16301633 if endpoint_type == EndpointType.INFERENCE_COMPONENT_BASED:
1634+ if update_endpoint:
1635+ raise ValueError(
1636+ "Currently update_endpoint is supported for single model endpoints"
1637+ )
16311638 if endpoint_name:
16321639 self.endpoint_name = endpoint_name
16331640 else:
@@ -1783,17 +1790,38 @@ def deploy(
17831790 if is_explainer_enabled:
17841791 explainer_config_dict = explainer_config._to_request_dict()
17851792
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- )
1793+ if update_endpoint:
1794+ endpoint_config_name = self.sagemaker_session.create_endpoint_config(
1795+ name=self.name,
1796+ model_name=self.name,
1797+ initial_instance_count=initial_instance_count,
1798+ instance_type=instance_type,
1799+ accelerator_type=accelerator_type,
1800+ tags=tags,
1801+ kms_key=kms_key,
1802+ data_capture_config_dict=data_capture_config_dict,
1803+ volume_size=volume_size,
1804+ model_data_download_timeout=model_data_download_timeout,
1805+ container_startup_health_check_timeout=container_startup_health_check_timeout,
1806+ explainer_config_dict=explainer_config_dict,
1807+ async_inference_config_dict=async_inference_config_dict,
1808+ serverless_inference_config=serverless_inference_config_dict,
1809+ routing_config=routing_config,
1810+ inference_ami_version=inference_ami_version,
1811+ )
1812+ self.sagemaker_session.update_endpoint(self.endpoint_name, endpoint_config_name)
1813+ else:
1814+ self.sagemaker_session.endpoint_from_production_variants(
1815+ name=self.endpoint_name,
1816+ production_variants=[production_variant],
1817+ tags=tags,
1818+ kms_key=kms_key,
1819+ wait=wait,
1820+ data_capture_config_dict=data_capture_config_dict,
1821+ explainer_config_dict=explainer_config_dict,
1822+ async_inference_config_dict=async_inference_config_dict,
1823+ live_logging=endpoint_logging,
1824+ )
17971825
17981826 if self.predictor_cls:
17991827 predictor = self.predictor_cls(self.endpoint_name, self.sagemaker_session)
0 commit comments