Additional Configurations for SageMaker Notebook Instance

Use of lifecircle configurations and git repositories


The SageMaker notebook instances include additional configurations such as Lifecycle configurations for environment configuration in the notebook instance, Git repositories for storing the project, and Network option for security.

Lifecycle Configuration

Lifecycle configuration contains shell scripts that run when we create or start a notebook instance. Lifecycle configurations can be configured such that necessary packages, setting paths or to access other resources for our kernel. We can create a new lifecycle configuration or use an existing one when we create a notebook instance.
info Lifecycle configuration examples - github-aws-sagemaker-notebook-instance-lifecycle-config-samples

Add Lifecycle Configuration during Notebook Instance creation

Lifecycle configuration can be added to a new notebook instance. We can add a new configuration or an existing configuration.
Select Create a new lifecycle configuration.


Lifecycle configuration includes two types of shell scripts. Create notebook scripts that are executed only during the creation of a notebook instance and Start notebook scripts that run every time a notebook instance starts. Here Start notebook script for stopping an idle notebook is added (Git-example-stop-notebook ).


Finally, Create configuration.

Update a Lifecycle Configuration

We can update the scripts in the lifecycle configuration.
Select the Lifecycle Configuration to be updated from Amazon SageMaker → Lifecycle configurations Menu.
Then edit the configuration.
The following example shows a Create notebook script to clone the TensorFlow git repository to the notebook instance.
Finally, Update. A new notebook instance with this configuration contains the TensorFlow-models directory.
The lifecycle configurations can be edited or create a clone and add commands to install extra packages.

Git Repositories

Git repositories save or access the projects in notebook instances when notebook instances are accidentally deleted or when they are stopped. We can use an external Git repository or the CodeCommit service by AWS.

Add Git Repositories during Notebook Instance creation

Git repositories can be added to the Notebook Instance during the creation or later. We can create a new AWS CodeCommit repository or add an external repository to the instance.

AWS CodeCommit

With CodeCommit, either we can create a new repository or add an existing one.

  1. Create a new repository
    Select Create a new repository → Add repository name →AWS CodeCommit → Create repository
    Now, Add repository
    In the CodeCommit service, we can see the new repository.
    Goto Services → CodeCommit

  2. Use existing repository
    Select Git Repositories → Add repository → AWS CodeCommit → Use existing repository
    Select a repository and add a unique name for the repository which is used in the SageMaker.
    Finally, Add repository.

External Git Repository

We can add external git-based repositories to SageMaker.
Select Git Repositories → Add repository → Github/Other Git-based repo→ Use existing repository
Add the Git credentials as a secret. A secret name is assigned to credentials that can be used in other repositories later. Enter the username and password. We can use existing secrets or if no credentials are required, use no secret.
Finally, Create Secret → Add repository.
info Amazon secret manager - AWS-Secret-Manager. This service helps to protect the information required to access the applications, services, and other resources. The credentials are stored using a secret name.
We can see the added repositories in SageMaker.
Finally, Create Notebook Instance. The notebook instance opens with the Git repo folder.
info In a notebook instance, we can have a default repository and associate up to 3 additional repositories as shown below.

Using Git Repositories in Notebook Instance

If a git repository is added to the notebook instance, we can use it from Terminal or Console.

  1. Terminal
    Notebook instances provide git terminal functionality. Git terminal commands can be used to track and modify the repositories. Use the option Git → Open Terminal in Git repository
    The terminal window opens with the git folder as the working directory. Here sagemaker-example is the local git repository.
    Using Git on the command line - Git- Command line

  2. Console

    • Repository structure using Git interface
    • New files will be shown in the Untracked menu
    • Adding files
      To add a file to the current branch, click on '+' symbol on the file. We can see this symbol when point the cursor on file. Here a file is added to the master branch.
    • Committing changes.
    • Pushing the changes to the repository.
      Click the Upload button.
      We can view the commits in AWS CodeCommit
    • Creating a new branch
      New Branch → Create Branch

Update Notebook Instances

Notebook instances can be updated even after creation. Addition/Deletion of all Notebook options are possible.
In order to update a notebook instance, select the notebook instance.
Amazon SageMaker → Notebook Instances → . Then edit the instance.
Here is an example of a change in the Git repository is illustrated. git-example-sagemaker is selected.
Next, Update notebook instance.
:warning: Be careful about notebook instance updates. Addition/Removal of configurations might affect the notebook properties.



Project State

Public Project


Software Licence: Project has no software
Hardware Licence: Project has no hardware

Project Tags




Does this project pique your interest?

Login or register to join or follow this project.

Back to top

Your comments, please!

Want to comment this ... Show more