Additional Configurations for SageMaker Notebook Instance

Use of lifecircle configurations and git repositories

Documentation

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.

notebook

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 ).

create_lifecircle_config

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.
edit
The following example shows a Create notebook script to clone the TensorFlow git repository to the notebook instance.
create_tf_clone_script
Finally, Update. A new notebook instance with this configuration contains the TensorFlow-models directory.
new_notebook
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.
create_git_notebook_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
    create_repo
    Now, Add repository
    In the CodeCommit service, we can see the new repository.
    Goto Services → CodeCommit
    code_commit

  2. Use existing repository
    Select Git Repositories → Add repository → AWS CodeCommit → Use existing repository
    existing_repo
    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_repo_external
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.
add_repo_to_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.
multiple_repos_in_notebook_instance

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
    open_terminal_in_repo
    The terminal window opens with the git folder as the working directory. Here sagemaker-example is the local git repository.
    local_git_repo
    Using Git on the command line - Git- Command line

  2. Console

    • Repository structure using Git interface
      git_instance
    • New files will be shown in the Untracked menu
      untracked
    • 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 README.md file is added to the master branch.
      git_add
    • Committing changes.
      git_commit
    • Pushing the changes to the repository.
      Click the Upload button.
      git_push
      We can view the commits in AWS CodeCommit
      CodeCommit
    • Creating a new branch
      New Branch → Create Branch
      new_branch1
      new_branch2

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.
select_notebook_update
update_notebook1
Here is an example of a change in the Git repository is illustrated. git-example-sagemaker is selected.
update_notebook2
Next, Update notebook instance.
:warning: Be careful about notebook instance updates. Addition/Removal of configurations might affect the notebook properties.

References

Info

Project State

Public Project

Licences

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

Project Tags

Admins

SelenaS
emeusel
Nina_Boehm
MeyerMel
TimM
nwilson
jstoltz
TomE

Members

Does this project pique your interest?

Login or register to join or follow this project.

Comments
Back to top

Your comments, please!

Want to comment this ... Show more