在 运行 任何代码之后,是否有我可以在 Sagemaker 上使用 "to stop" Notebook 实例的 Jupyter 代码?

Is there a Jupyter code that I can use "to stop" a Notebook Instances on Sagemaker, after running any code?

我在 Sagemaker 上使用 Jupyter Notebook 实例来 运行 一个代码,大约需要 3 个小时才能完成。由于我按小时使用付费,因此我想自动 "Close and Halt" Notebook 并在 运行 执行该代码后停止 "Notebook instance"。这可能吗?

Jupyter Notebook 主要设计用于探索和 发展。如果您想启动 long-运行 或预定作业 短暂的硬件,使用它会是一个更好的体验 训练API,比如boto3中的create_training_job或者 estimator.fit()Python SDK。传递给训练作业的代码 可以是完全任意的——不一定是 ML 代码——所以不管 你在 jupyter 中写的可能会被安排并且 运行 在那些 培训工作。请参阅 random forest sklearn demo here 例子。话虽这么说,如果你仍然想以编程方式关闭 在 SageMaker notebook 实例下,您可以使用该 boto3 调用:

import boto3

sm = boto3.client('sagemaker')
sm.stop_notebook_instance(NotebookInstanceName='string')