@@ -83,7 +83,13 @@ def pipeline_container_def(self, instance_type):
83
83
return sagemaker .pipeline_container_def (self .models , instance_type )
84
84
85
85
def deploy (
86
- self , initial_instance_count , instance_type , endpoint_name = None , tags = None , wait = True
86
+ self ,
87
+ initial_instance_count ,
88
+ instance_type ,
89
+ endpoint_name = None ,
90
+ tags = None ,
91
+ wait = True ,
92
+ update_endpoint = False ,
87
93
):
88
94
"""Deploy this ``Model`` to an ``Endpoint`` and optionally return a
89
95
``Predictor``.
@@ -110,6 +116,11 @@ def deploy(
110
116
specific endpoint.
111
117
wait (bool): Whether the call should wait until the deployment of
112
118
model completes (default: True).
119
+ update_endpoint (bool): Flag to update the model in an existing
120
+ Amazon SageMaker endpoint. If True, this will deploy a new
121
+ EndpointConfig to an already existing endpoint and delete
122
+ resources corresponding to the previous EndpointConfig. If
123
+ False, a new endpoint will be created. Default: False
113
124
114
125
Returns:
115
126
callable[string, sagemaker.session.Session] or None: Invocation of
@@ -130,9 +141,21 @@ def deploy(
130
141
self .name , instance_type , initial_instance_count
131
142
)
132
143
self .endpoint_name = endpoint_name or self .name
133
- self .sagemaker_session .endpoint_from_production_variants (
134
- self .endpoint_name , [production_variant ], tags , wait = wait
135
- )
144
+
145
+ if update_endpoint :
146
+ endpoint_config_name = self .sagemaker_session .create_endpoint_config (
147
+ name = self .name ,
148
+ model_name = self .name ,
149
+ initial_instance_count = initial_instance_count ,
150
+ instance_type = instance_type ,
151
+ tags = tags ,
152
+ )
153
+ self .sagemaker_session .update_endpoint (self .endpoint_name , endpoint_config_name )
154
+ else :
155
+ self .sagemaker_session .endpoint_from_production_variants (
156
+ self .endpoint_name , [production_variant ], tags , wait = wait
157
+ )
158
+
136
159
if self .predictor_cls :
137
160
return self .predictor_cls (self .endpoint_name , self .sagemaker_session )
138
161
return None
0 commit comments