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 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.
Lifecycle configuration examples - github-aws-sagemaker-notebook-instance-lifecycle-config-samples
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.
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 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.
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.
With CodeCommit, either we can create a new repository or add an existing one.
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
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.
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.
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.
In a notebook instance, we can have a default repository and associate up to 3 additional repositories as shown below.
If a git repository is added to the notebook instance, we can use it from Terminal or Console.
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
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.