Notebook Lifecycle Config create, describe and delete (#3417)

* Notebook Lifecycle Config create, describe and delete

* PR3417 comment changes: raise on create with duplicate name, derive a ValidationException class and use it instead of RESTException, unit test for delete non-existing.

Co-authored-by: Joseph Weitekamp <jweite@amazon.com>
This commit is contained in:
jweite 2020-10-30 17:05:06 -04:00 committed by GitHub
commit f8d2ce2e6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 220 additions and 94 deletions

View file

@ -225,3 +225,68 @@ def test_describe_nonexistent_model():
assert_true(
e.exception.response["Error"]["Message"].startswith("Could not find model")
)
@mock_sagemaker
def test_notebook_instance_lifecycle_config():
sagemaker = boto3.client("sagemaker", region_name=TEST_REGION_NAME)
name = "MyLifeCycleConfig"
on_create = [{"Content": "Create Script Line 1"}]
on_start = [{"Content": "Start Script Line 1"}]
resp = sagemaker.create_notebook_instance_lifecycle_config(
NotebookInstanceLifecycleConfigName=name, OnCreate=on_create, OnStart=on_start
)
assert_true(
resp["NotebookInstanceLifecycleConfigArn"].startswith("arn:aws:sagemaker")
)
assert_true(resp["NotebookInstanceLifecycleConfigArn"].endswith(name))
with assert_raises(ClientError) as e:
resp = sagemaker.create_notebook_instance_lifecycle_config(
NotebookInstanceLifecycleConfigName=name,
OnCreate=on_create,
OnStart=on_start,
)
assert_true(
e.exception.response["Error"]["Message"].endswith(
"Notebook Instance Lifecycle Config already exists.)"
)
)
resp = sagemaker.describe_notebook_instance_lifecycle_config(
NotebookInstanceLifecycleConfigName=name,
)
assert_equal(resp["NotebookInstanceLifecycleConfigName"], name)
assert_true(
resp["NotebookInstanceLifecycleConfigArn"].startswith("arn:aws:sagemaker")
)
assert_true(resp["NotebookInstanceLifecycleConfigArn"].endswith(name))
assert_equal(resp["OnStart"], on_start)
assert_equal(resp["OnCreate"], on_create)
assert_true(isinstance(resp["LastModifiedTime"], datetime.datetime))
assert_true(isinstance(resp["CreationTime"], datetime.datetime))
sagemaker.delete_notebook_instance_lifecycle_config(
NotebookInstanceLifecycleConfigName=name,
)
with assert_raises(ClientError) as e:
sagemaker.describe_notebook_instance_lifecycle_config(
NotebookInstanceLifecycleConfigName=name,
)
assert_true(
e.exception.response["Error"]["Message"].endswith(
"Notebook Instance Lifecycle Config does not exist.)"
)
)
with assert_raises(ClientError) as e:
sagemaker.delete_notebook_instance_lifecycle_config(
NotebookInstanceLifecycleConfigName=name,
)
assert_true(
e.exception.response["Error"]["Message"].endswith(
"Notebook Instance Lifecycle Config does not exist.)"
)
)