Skip to content

Commit 535435a

Browse files
authored
Add delete_endpoint() method for tuner (aws#48)
1 parent 619a8c9 commit 535435a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/sagemaker/tuner.py

+12
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ def best_training_job(self):
208208
except KeyError:
209209
raise Exception('Best training job not available for tuning job: {}'.format(self.latest_tuning_job.name))
210210

211+
def delete_endpoint(self, endpoint_name=None):
212+
"""Delete an Amazon SageMaker endpoint.
213+
214+
If an endpoint name is not specified, this defaults to looking for an endpoint that
215+
shares a name with the best training job for deletion.
216+
217+
Args:
218+
endpoint_name (str): Name of the endpoint to delete
219+
"""
220+
endpoint_name = endpoint_name or self.best_training_job()
221+
self.sagemaker_session.delete_endpoint(endpoint_name)
222+
211223
def _ensure_last_tuning_job(self):
212224
if self.latest_tuning_job is None:
213225
raise ValueError('No tuning job available')

tests/unit/test_tuner.py

+11
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,17 @@ def test_wait(tuner):
432432
tuner.estimator.sagemaker_session.wait_for_tuning_job.assert_called_once_with(JOB_NAME)
433433

434434

435+
def test_delete_endpoint(tuner):
436+
tuner.latest_tuning_job = _TuningJob(tuner.estimator.sagemaker_session, JOB_NAME)
437+
438+
tuning_job_description = {'BestTrainingJob': {'TrainingJobName': JOB_NAME}}
439+
tuner.estimator.sagemaker_session.sagemaker_client.describe_hyper_parameter_tuning_job = Mock(
440+
name='describe_hyper_parameter_tuning_job', return_value=tuning_job_description)
441+
442+
tuner.delete_endpoint()
443+
tuner.sagemaker_session.delete_endpoint.assert_called_with(JOB_NAME)
444+
445+
435446
#################################################################################
436447
# _ParameterRange Tests
437448

0 commit comments

Comments
 (0)