Skip to content

create_notebook_instance_lifecycle_config async

create_notebook_instance_lifecycle_config(
    *,
    config_overrides: Optional[AsyncSageMakerClientConfig] = None,
    notebook_instance_lifecycle_config_name: Optional[
        NotebookInstanceLifecycleConfigName
    ] = None,
    on_create: Optional[NotebookInstanceLifecycleConfigList] = None,
    on_start: Optional[NotebookInstanceLifecycleConfigList] = None,
    tags: Optional[TagList] = None,
) -> CreateNotebookInstanceLifecycleConfigOutput

Creates a lifecycle configuration that you can associate with a notebook instance. A lifecycle configuration is a collection of shell scripts that run when you create or start a notebook instance.

Each lifecycle configuration script has a limit of 16384 characters.

The value of the $PATH environment variable that is available to both scripts is /sbin:bin:/usr/sbin:/usr/bin.

View Amazon CloudWatch Logs for notebook instance lifecycle configurations in log group /aws/sagemaker/NotebookInstances in log stream [notebook-instance-name]/[LifecycleConfigHook].

Lifecycle configuration scripts cannot run for longer than 5 minutes. If a script runs for longer than 5 minutes, it fails and the notebook instance is not created or started.

For information about notebook instance lifestyle configurations, see Step 2.1: (Optional) Customize a Notebook Instance.

Lifecycle configuration scripts execute with root access and the notebook instance's IAM execution role privileges. Grant this permission only to trusted principals. See Customize a Notebook Instance Using a Lifecycle Configuration Script for security best practices.

Parameters:

Raises:

  • ResourceLimitExceeded –

    You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_sagemaker/_services/async_sage_maker.py
async def create_notebook_instance_lifecycle_config(
    self,
    *,
    config_overrides: Optional[AsyncSageMakerClientConfig] = None,
    notebook_instance_lifecycle_config_name: Optional[
        "capo_sagemaker.types.notebook_instance_lifecycle_config_name.NotebookInstanceLifecycleConfigName"
    ] = None,
    on_create: Optional[
        "capo_sagemaker.types.notebook_instance_lifecycle_config_list.NotebookInstanceLifecycleConfigList"
    ] = None,
    on_start: Optional[
        "capo_sagemaker.types.notebook_instance_lifecycle_config_list.NotebookInstanceLifecycleConfigList"
    ] = None,
    tags: Optional["capo_sagemaker.types.tag_list.TagList"] = None,
) -> "capo_sagemaker.types.create_notebook_instance_lifecycle_config_output.CreateNotebookInstanceLifecycleConfigOutput":
    """<p>Creates a lifecycle configuration that you can associate with a notebook instance. A <i>lifecycle configuration</i> is a collection of shell scripts that run when you create or start a notebook instance.</p> <p>Each lifecycle configuration script has a limit of 16384 characters.</p> <p>The value of the <code>$PATH</code> environment variable that is available to both scripts is <code>/sbin:bin:/usr/sbin:/usr/bin</code>.</p> <p>View Amazon CloudWatch Logs for notebook instance lifecycle configurations in log group <code>/aws/sagemaker/NotebookInstances</code> in log stream <code>[notebook-instance-name]/[LifecycleConfigHook]</code>.</p> <p>Lifecycle configuration scripts cannot run for longer than 5 minutes. If a script runs for longer than 5 minutes, it fails and the notebook instance is not created or started.</p> <p>For information about notebook instance lifestyle configurations, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/notebook-lifecycle-config.html">Step 2.1: (Optional) Customize a Notebook Instance</a>.</p> <note> <p>Lifecycle configuration scripts execute with root access and the notebook instance's IAM execution role privileges. Grant this permission only to trusted principals. See <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/notebook-lifecycle-config.html">Customize a Notebook Instance Using a Lifecycle Configuration Script</a> for security best practices.</p> </note>

    Args:
        notebook_instance_lifecycle_config_name: <p>The name of the lifecycle configuration.</p>
        on_create: <p>A shell script that runs only once, when you create a notebook instance. The shell script must be a base64-encoded string.</p>
        on_start: <p>A shell script that runs every time you start a notebook instance, including when you create the notebook instance. The shell script must be a base64-encoded string.</p>
        tags: <p>An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see <a href="https://docs.aws.amazon.com/tag-editor/latest/userguide/tagging.html">Tagging Amazon Web Services Resources</a>.</p>

    Raises:
        capo_sagemaker.errors.resource_limit_exceeded.ResourceLimitExceeded: <p> You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. </p>
        capo_sagemaker.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_sagemaker.types.create_notebook_instance_lifecycle_config_input.CreateNotebookInstanceLifecycleConfigInput]",
    ) -> AsyncOperationResponse[
        "capo_sagemaker.types.create_notebook_instance_lifecycle_config_output.CreateNotebookInstanceLifecycleConfigOutput"
    ]:
        import capo_sagemaker._operations.sage_maker.create_notebook_instance_lifecycle_config

        (
            output,
            http_response,
        ) = await capo_sagemaker._operations.sage_maker.create_notebook_instance_lifecycle_config.async_create_notebook_instance_lifecycle_config(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateNotebookInstanceLifecycleConfig")
    )
    input_: capo_sagemaker.types.create_notebook_instance_lifecycle_config_input.CreateNotebookInstanceLifecycleConfigInput = {}
    if notebook_instance_lifecycle_config_name is not None:
        input_["notebook_instance_lifecycle_config_name"] = (
            notebook_instance_lifecycle_config_name
        )
    if on_create is not None:
        input_["on_create"] = on_create
    if on_start is not None:
        input_["on_start"] = on_start
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output