

# Use the Amazon SageMaker Studio Lab project runtime
<a name="studio-lab-use"></a>

 The following topics give information about using the Amazon SageMaker Studio Lab project runtime. Before you can use the Studio Lab project runtime, you must onboard to Studio Lab by following the steps in [Onboard to Amazon SageMaker Studio Lab](studio-lab-onboard.md).

**Topics**
+ [Amazon SageMaker Studio Lab UI overview](studio-lab-use-ui.md)
+ [Create or open an Amazon SageMaker Studio Lab notebook](studio-lab-use-create.md)
+ [Use the Amazon SageMaker Studio Lab notebook toolbar](studio-lab-use-menu.md)
+ [Manage your environment](studio-lab-use-manage.md)
+ [Use external resources in Amazon SageMaker Studio Lab](studio-lab-use-external.md)
+ [Get notebook differences](studio-lab-use-diff.md)
+ [Export an Amazon SageMaker Studio Lab environment to Amazon SageMaker Studio Classic](studio-lab-use-migrate.md)
+ [Shut down Studio Lab resources](studio-lab-use-shutdown.md)

# Amazon SageMaker Studio Lab UI overview
<a name="studio-lab-use-ui"></a>

Amazon SageMaker Studio Lab extends the JupyterLab interface. Previous users of JupyterLab will notice similarities between the JupyterLab and Studio Lab UI, including the workspace. For an overview of the basic JupyterLab interface, see [The JupyterLab Interface](https://jupyterlab.readthedocs.io/en/latest/user/interface.html).

The following image shows Studio Lab with the file browser open and the Studio Lab Launcher displayed.

![\[The layout of the project user interface.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio-lab-ui.png)


You will find the *menu bar* at the top of the screen. The *left sidebar* contains icons to open file browsers, resource browsers, and tools. The *status bar* is located at the bottom-left corner of Studio Lab.

The main work area is divided horizontally into two panes. The left pane is the *file and resource browser*. The right pane contains one or more tabs for resources, such as notebooks and terminals.

**Topics**
+ [Left sidebar](#studio-lab-use-ui-nav-bar)
+ [File and resource browser](#studio-lab-use-ui-browser)
+ [Main work area](#studio-lab-use-ui-work)

## Left sidebar
<a name="studio-lab-use-ui-nav-bar"></a>

The left sidebar includes the following icons. When you hover over an icon, a tooltip displays the icon name. When you choose an icon, the file and resource browser displays the described functionality. For hierarchical entries, a selectable breadcrumb at the top of the browser shows your location in the hierarchy.


| Icon | Description | 
| --- | --- | 
|  ![\[The File Browser icon\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/File_browser_squid@2x.png)  |  **File Browser** Choose the **Upload Files** icon (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/File_upload_squid.png)) to add files to Studio Lab. Double-click a file to open the file in a new tab. To have adjacent files open, choose a tab that contains a notebook, Python, or text file, and then choose **New View for File**. Choose the plus (**\$1**) sign on the menu at the top of the file browser to open the Studio Lab Launcher.  | 
|  ![\[The Running Terminals and Kernels icon\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/Running_squid@2x.png)  |  **Running Terminals and Kernels** You can see a list of all of the running terminals and kernels in your project. For more information, see [Shut down Studio Lab resources](studio-lab-use-shutdown.md).  | 
|  ![\[The Git icon\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/Git_squid@2x.png)  |  **Git** You can connect to a Git repository and then access a full range of Git tools and operations. For more information, see [Use external resources in Amazon SageMaker Studio Lab](studio-lab-use-external.md).  | 
|  ![\[The Table of Contents icon\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-toc.png)  |  **Table of Contents** You can access the Table of Contents for your current Jupyter notebook.  | 
|  ![\[The Extension Manager icon\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-extension.png)  |  **Extension Manager** You can enable and manage third-party JupyterLab extensions.  | 

## File and resource browser
<a name="studio-lab-use-ui-browser"></a>

The file and resource browser shows lists of your notebooks and files. On the menu at the top of the file browser, choose the plus (**\$1**) sign to open the Studio Lab Launcher. The Launcher allows you to create a notebook or open a terminal.

## Main work area
<a name="studio-lab-use-ui-work"></a>

The main work area has multiple tabs that contain your open notebooks and terminals.

# Create or open an Amazon SageMaker Studio Lab notebook
<a name="studio-lab-use-create"></a>

When you create a notebook in Amazon SageMaker Studio Lab or open a notebook in Studio Lab, you must select a kernel for the notebook. The following topics describe how to create and open notebooks in Studio Lab.

For information about shutting down the notebook, see [Shut down Studio Lab resources](studio-lab-use-shutdown.md).

**Topics**
+ [Open a Studio Lab notebook](#studio-lab-use-create-open)
+ [Create a notebook from the file menu](#studio-lab-use-create-file)
+ [Create a notebook from the Launcher](#studio-lab-use-create-launcher)

## Open a Studio Lab notebook
<a name="studio-lab-use-create-open"></a>

Studio Lab can only open notebooks listed in the Studio Lab file browser. To clone a notebook into your file browser from an external repository, see [Use external resources in Amazon SageMaker Studio Lab](studio-lab-use-external.md).

**To open a notebook**

1. In the left sidebar, choose the **File Browser** icon (![\[Dark blue square icon with a white outline of a cloud and an arrow pointing upward.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/File_browser_squid.png)) to display the file browser.

1. Browse to a notebook file and double-click it to open the notebook in a new tab.

## Create a notebook from the file menu
<a name="studio-lab-use-create-file"></a>

**To create a notebook from the File menu**

1. From the Studio Lab menu, choose **File**, choose **New**, and then choose **Notebook**.

1. To use the default kernel, in the **Select Kernel** dialog box, choose **Select**. Otherwise, to select a different kernel, use the dropdown menu.

## Create a notebook from the Launcher
<a name="studio-lab-use-create-launcher"></a>

**To create a notebook from the Launcher**

1. Open the Launcher by using the keyboard shortcut `Ctrl + Shift + L`.

   Alternatively, you can open Launcher from the left sidebar: Choose the **File Browser** icon, and then choose the plus (**\$1**) icon.

1. To use the default kernel from the Launcher, under **Notebook**, choose **default:Python**. Otherwise, select a different kernel.

After you choose the kernel, your notebook launches and opens in a new Studio Lab tab. 

To view the notebook's kernel session, in the left sidebar, choose the **Running Terminals and Kernels** icon (![\[Square icon with a white outline of a cloud on a dark blue background.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/Running_squid.png)). You can stop the notebook's kernel session from this view.

# Use the Amazon SageMaker Studio Lab notebook toolbar
<a name="studio-lab-use-menu"></a>

Amazon SageMaker Studio Lab notebooks extend the JupyterLab interface. For an overview of the basic JupyterLab interface, see [The JupyterLab Interface](https://jupyterlab.readthedocs.io/en/latest/user/interface.html).

The following image shows the toolbar and an empty cell from a Studio Lab notebook.

![\[The layout of the notebook toolbar, including the toolbar icons.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio-lab-menu.png)


When you hover over a toolbar icon, a tooltip displays the icon function. You can find additional notebook commands in the Studio Lab main menu. The toolbar includes the following icons:


| Icon | Description | 
| --- | --- | 
|  ![\[The Save and checkpoint icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-save-and-checkpoint.png)  |  **Save and checkpoint** Saves the notebook and updates the checkpoint file.  | 
|  ![\[The Insert cell icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-insert-cell.png)  |  **Insert cell** Inserts a code cell below the current cell. The current cell is noted by the blue vertical marker in the left margin.  | 
|  ![\[The Cut, copy, and paste cells icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab_cut_copy_paste.png)  |  **Cut, copy, and paste cells** Cuts, copies, and pastes the selected cells.  | 
|  ![\[The Run cells icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-run.png)  |  **Run cells** Runs the selected cells. The cell that follows the last-selected cell becomes the new-selected cell.  | 
|  ![\[The Interrupt kernel icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-interrupt-kernel.png)  |  **Interrupt kernel** Interrupts the kernel, which cancels the currently-running operation. The kernel remains active.  | 
|  ![\[The Restart kernel icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-restart-kernel.png)  |  **Restart kernel** Restarts the kernel. Variables are reset. Unsaved information is not affected.  | 
|  ![\[The Restart kernel and re-run notebook icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-restart-rerun-kernel.png)  |  **Restart kernel and re-run notebook** Restarts the kernel. Variables are reset. Unsaved information is not affected. Then re-runs the entire notebook.  | 
|  ![\[The Cell type icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab_cell.png)  |  **Cell type** Displays or changes the current cell type. The cell types are: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/sagemaker/latest/dg/studio-lab-use-menu.html)  | 
|  ![\[The Checkpoint diff icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-checkpoint-diff.png)  |  **Checkpoint diff** Opens a new tab that displays the difference between the notebook and the checkpoint file. For more information, see [Get notebook differences](studio-lab-use-diff.md).  | 
|  ![\[The Git diff icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-git-diff.png)  |  **Git diff** Only enabled if the notebook is opened from a Git repository. Opens a new tab that displays the difference between the notebook and the last Git commit. For more information, see [Get notebook differences](studio-lab-use-diff.md).  | 
|  **default**  |  **Kernel** Displays or changes the kernel that processes the cells in the notebook. `No Kernel` indicates that the notebook was opened without specifying a kernel. You can edit the notebook, but you can't run any cells.  | 
|  ![\[The Kernel busy status icon.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/studio-lab-kernel.png)  |  **Kernel busy status** Displays a kernel's busy status by showing the circle's edge and its interior as the same color. The kernel is busy when it is starting and when it is processing cells. Additional kernel states are displayed in the status bar at the bottom-left corner of Studio Lab.  | 

# Manage your environment
<a name="studio-lab-use-manage"></a>

Amazon SageMaker Studio Lab provides pre-installed environments for your Studio Lab notebook instances. Environments allow you to start up a Studio Lab notebook instance with the packages you want to use. This is done by installing packages in the environment and then selecting the environment as a Kernel. 

Studio Lab has various environments pre-installed for you. You will typically want to use the `sagemaker-distribution` environment if you want to use a fully managed environment that already contains many popular packages used for machine learning (ML) engineers and data scientists. Otherwise you can use the `default` environment if you want persistent customization for your environment. For more information on the available pre-installed Studio Lab environments, see [Studio Lab pre-installed environments](studio-lab-environments.md).

You can customize your environment by adding new packages (or libraries) to it. You can also create new environments from Studio Lab, import compatible environments, reset your environment to create space, and more. 

The following commands are for running in a Studio Lab terminal. However, while installing packages it is highly recommended to install them within your Studio Lab Jupyter notebook. This ensures that the packages are installed in the intended environment. To run the commands in a Jupyter notebook, prefix the command with a `%` before running the cell. For example, the code snippet `pip list` in a terminal is the same as `%pip list` in a Jupyter notebook.

The following sections give information about your `default` conda environment, how to customize it, and how to add and remove conda environments. For a list of sample environments that you can install into Studio Lab, see [Creating Custom conda Environments](https://github.com/aws/studio-lab-examples/tree/main/custom-environments). To use these sample environment YAML files with Studio Lab, see [Step 4: Install your Studio Lab conda environments in Studio Classic](studio-lab-use-migrate.md#studio-lab-use-migrate-step4). 

**Topics**
+ [Your default environment](#studio-lab-use-manage-conda-default)
+ [View environments](#studio-lab-use-view-conda-envs)
+ [Create, activate, and use new conda environments](#studio-lab-use-manage-conda-new-conda)
+ [Using sample Studio Lab environments](#studio-lab-use-manage-conda-sample)
+ [Customize your environment](#studio-lab-use-manage-conda-default-customize)
+ [Refresh Studio Lab](#studio-lab-use-manage-conda-reset)

## Your default environment
<a name="studio-lab-use-manage-conda-default"></a>

Studio Lab uses conda environments to encapsulate the software packages that are needed to run notebooks. Your project contains a default conda environment, named `default`, with the [IPython kernel](https://ipython.readthedocs.io/en/stable/). This environment serves as the default kernel for your Jupyter notebooks.

## View environments
<a name="studio-lab-use-view-conda-envs"></a>

To view the environments in Studio Lab you can use a terminal or Jupyter notebook. The following command will be for a Studio Lab terminal. If you wish to run the corresponding commands in a Jupyter notebook, see [Manage your environment](#studio-lab-use-manage).

Open the Studio Lab terminal by opening the **File Browser** panel (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/folder.png)), choose the plus (**\$1**) sign on the menu at the top of the file browser to open the **Launcher**, then choose **Terminal**. From the Studio Lab terminal, list the conda environments by running the following.

```
conda env list
```

This command outputs a list of the conda environments and their locations in the file system. When you onboard to Studio Lab, you automatically activate the `studiolab`  conda environment. The following is an example of listed environments after you onboard.

```
# conda environments:
#
default                  /home/studio-lab-user/.conda/envs/default
studiolab             *  /home/studio-lab-user/.conda/envs/studiolab
studiolab-safemode       /opt/amazon/sagemaker/safemode-home/.conda/envs/studiolab-safemode
base                     /opt/conda
sagemaker-distribution     /opt/conda/envs/sagemaker-distribution
```

The `*` marks the activated environment.

## Create, activate, and use new conda environments
<a name="studio-lab-use-manage-conda-new-conda"></a>

If you would like to maintain multiple environments for different use cases, you can create new conda environments in your project. The following sections show how to create and activate new conda environments. For a Jupyter notebook that shows how to create a custom environment, see [Setting up a Custom Environment in SageMaker Studio Lab](https://github.com/aws/studio-lab-examples/blob/main/custom-environments/custom_environment.ipynb).

**Note**  
Maintaining multiple environments counts against your available Studio Lab memory.

 **Create conda environment** 

To create a conda environment, run the following conda command from your terminal. This example creates a new environment with Python 3.9. 

```
conda create --name <ENVIRONMENT_NAME> python=3.9
```

Once the conda environment is created, you can view the environment in your environment list. For more information on how to view your environment list, see [View environments](#studio-lab-use-view-conda-envs).

 **Activate a conda environment** 

To activate any conda environment, run the following command in the terminal.

```
conda activate <ENVIRONMENT_NAME>
```

When you run this command, any packages installed using conda or pip are installed in the environment. For more information on installing packages, see [Customize your environment](#studio-lab-use-manage-conda-default-customize).

 **Use a conda environment** 

1. To use your new conda environments with notebooks, make sure the `ipykernel` package is installed in the environment.

   ```
   conda install ipykernel
   ```

1. Once the `ipykernel` package is installed in the environment, you can select the environment as the kernel for your notebook. 

   You may need to restart JupyterLab to see the environment available as a kernel. This can be done by choosing **Amazon SageMaker Studio Lab** in the top menu of your Studio Lab open project, and choosing **Restart JupyterLab...**. 

1. You can choose the kernel for an existing notebook or when you create a new one.
   + For an existing notebook: open the notebook and choose the current kernel from the right side of the top menu. You can choose the kernel you wish to use from the drop-down menu.
   + For a new notebook: open the Studio Lab launcher and choose the kernel under **Notebook**. This will open the notebook with the kernel you choose.

     For an overview of the Studio Lab UI, see [Amazon SageMaker Studio Lab UI overview](studio-lab-use-ui.md).

## Using sample Studio Lab environments
<a name="studio-lab-use-manage-conda-sample"></a>

Studio Lab provides sample custom environments through the [SageMaker Studio Lab Examples](https://github.com/aws/studio-lab-examples) repository. The following shows how to clone and build these environments.

1. Clone the SageMaker Studio Lab Examples GitHub repository by following the instructions in [Use GitHub resources](studio-lab-use-external.md#studio-lab-use-external-clone-github).

1. In Studio Lab choose the **File Browser** icon (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/folder.png)) on the left menu, so that the **File Browser** panel shows on the left.

1. Navigate to the `studio-lab-examples/custom-environments` directory in the File Browser.

1. Open the directory for the environment that you want to build.

1. Right click the `.yml` file in the folder, then select **Build conda Environment**.

1. You can now use the environment as a kernel after your conda environment has finished building. For instructions on how to use an existing environment as a kernel, see [Create, activate, and use new conda environments](#studio-lab-use-manage-conda-new-conda)

## Customize your environment
<a name="studio-lab-use-manage-conda-default-customize"></a>

You can customize your environment by installing and removing extensions and packages as needed. Studio Lab comes with environments with packages pre-installed and using an existing environment may save you time and memory, as pre-installed packages do not count against your available Studio Lab memory. For more information on the available pre-installed Studio Lab environments, see [Studio Lab pre-installed environments](studio-lab-environments.md).

Any installed extensions and packages installed on your `default` environment will persist in your project. That is, you do not need to install your packages for every project runtime session. However, extensions and packages installed on your `sagemaker-distribution` environment will not persist, so you will need to install new packages during your next session. Thus, it is highly recommended to install packages within your notebook to ensure that the packages are installed in the intended environment.

To view your environments, run the command `conda env list`.

To activate your environment, run the command `conda activate <ENVIRONMENT_NAME>`.

To view the packages in an environment, run the command `conda list`.

 **Install packages** 

It is highly recommended to install your packages within your Jupyter notebook to ensure that your packages are installed in the intended environment. To install additional packages to your environment from a Jupyter notebook, run one of the following commands in a cell within your Jupyter notebook. These commands install packages in the currently activated environment. 
+  `%conda install <PACKAGE>` 
+  `%pip install <PACKAGE>` 

We don't recommend using the `!pip` or `!conda` commands because they can behave in unexpected ways when you have multiple environments. 

After you install new packages to your environment, you may need to restart the kernel to ensure that the packages work in your notebook. This can be done by choosing **Amazon SageMaker Studio Lab** in the top menu of your Studio Lab open project and choosing **Restart JupyterLab...**. 

 **Remove packages** 

To remove a package, run the command

```
%conda remove <PACKAGE_NAME>
```

This command will also remove any package that depends on `<PACKAGE_NAME>`, unless a replacement can be found without that dependency. 

To remove all of the packages in an environment, run the command

```
conda deactivate
&& conda env remove --name
<ENVIRONMENT_NAME>
```

## Refresh Studio Lab
<a name="studio-lab-use-manage-conda-reset"></a>

To refresh Studio Lab, remove all of your environments and files. 

1. List all conda environments.

   ```
   conda env list
   ```

1. Activate the base environment.

   ```
   conda activate base
   ```

1. Remove each environment in the list of conda environments, besides base.

   ```
   conda remove --name <ENVIRONMENT_NAME> --all
   ```

1. Delete all of the files on your Studio Lab.

   ```
   rm -rf *.*
   ```

# Use external resources in Amazon SageMaker Studio Lab
<a name="studio-lab-use-external"></a>

With Amazon SageMaker Studio Lab, you can integrate external resources, such as Jupyter notebooks and data, from Git repositories and Amazon S3. You can also add an **Open in Studio Lab** button to your GitHub repo and notebooks. This button lets you clone your notebooks directly from Studio Lab.

The following topics show how to integrate external resources.

**Topics**
+ [Use GitHub resources](#studio-lab-use-external-clone-github)
+ [Add an **Open in Studio Lab** button to your notebook](#studio-lab-use-external-add-button)
+ [Import files from your computer](#studio-lab-use-external-import)
+ [Connect to Amazon S3](#studio-lab-use-external-s3)

## Use GitHub resources
<a name="studio-lab-use-external-clone-github"></a>

Studio Lab offers integration with GitHub. With this integration, you can clone notebooks and repositories directly to your Studio Lab project. 

The following topics give information about how to use GitHub resources with Studio Lab.

### Studio Lab sample notebooks
<a name="studio-lab-use-external-clone-examples"></a>

To get started with a repository of sample notebooks tailored for Studio Lab, see [Studio Lab Sample Notebooks](https://github.com/aws/studio-lab-examples#sagemaker-studio-lab-sample-notebooks).

This repository provides notebooks for the following use cases and others.
+ Computer vision
+ Connecting to AWS
+ Creating custom environments
+ Geospatial data analysis
+ Natural language processing
+ Using R

### Clone a GitHub repo
<a name="studio-lab-use-external-clone-repo"></a>

To clone a GitHub repo to your Studio Lab project, follow these steps. 

1. Start your Studio Lab project runtime. For more information on launching Studio Lab project runtime, see [Start your project runtime](studio-lab-manage-runtime.md#studio-lab-manage-runtime-start). 

1. In Studio Lab, choose the **File Browser** icon (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/folder.png)) on the left menu, so that the **File Browser** panel shows on the left. 

1. Navigate to your user directory by choosing the file icon beneath the file search bar. 

1. Select the **Git** icon (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/git.png)) from the left menu to open a new dropdown menu. 

1. Choose **Clone a Repository**. 

1. Paste the repository's URL under **Git repository URL (.git)**. 

1. Select **Clone**. 

### Clone individual notebooks from GitHub
<a name="studio-lab-use-external-clone-individual"></a>

To open a notebook in Studio Lab, you must have access to the repo that the notebook is in. The following examples describe Studio Lab permission-related behavior in various situations.
+ If a repo is public, you can automatically clone the notebook into your project from the Studio Lab preview page.
+ If a repo is private, you are prompted to sign in to GitHub from the Studio Lab preview page. If you have access to a private repo, you can clone the notebook into your project.
+ If you don't have access to a private repo, you cannot clone the notebook from the Studio Lab preview page.

The following sections show two options for you to copy a GitHub notebook in your Studio Lab project. These options depend on whether the notebook has an **Open in Studio Lab** button. 

#### Option 1: Copy notebook with an **Open in Studio Lab** button
<a name="studio-lab-use-external-clone-individual-button"></a>

The following procedure shows how to copy a notebook that has an **Open in Studio Lab** button. If you want to add this button to your notebook, see [Add an **Open in Studio Lab** button to your notebook](#studio-lab-use-external-add-button).

1. Sign in to Studio Lab following the steps in [Sign in to Studio Lab](studio-lab-onboard.md#studio-lab-onboard-signin).

1. In a new browser tab, navigate to the GitHub notebook that you want to clone. 

1. In the notebook, select the **Open in Studio Lab** button to open a new page in Studio Lab with a preview of the notebook.

1. If your project runtime is not already running, start it by choosing the **Start runtime** button at the top of the preview page. Wait for the runtime to start before proceeding to the next step.

1. After your project runtime has started, select **Copy to project** to open your project runtime in a new browser tab. 

1. In the **Copy from GitHub?** dialog box, select **Copy notebook only**. This copies the notebook file to your project.

#### Option 2: Clone any GitHub notebook
<a name="studio-lab-use-external-clone-individual-general"></a>

The following procedure shows how to copy any notebook from GitHub. 

1. Navigate to the notebook in GitHub. 

1. In the browser’s address bar, modify the notebook URL, as follows.

   ```
   # Original URL
   https://github.com/<PATH_TO_NOTEBOOK>
   
   # Modified URL 
   https://studiolab.sagemaker.aws/import/github/<PATH_TO_NOTEBOOK>
   ```

1. Navigate to the modified URL. This opens a preview of the notebook in Studio Lab. 

1. If your project runtime is not already running, start it by choosing the **Start runtime** button at the top of the preview page. Wait for the runtime to start before proceeding to the next step. 

1. After your project runtime has started, select **Copy to project** to open your project runtime in a new browser tab. 

1. In the **Copy from GitHub?** dialog box, select **Copy notebook only** to copy the notebook file to your project.

## Add an **Open in Studio Lab** button to your notebook
<a name="studio-lab-use-external-add-button"></a>

When you add the **Open in Studio Lab** button to your notebooks, others can clone your notebooks or repositories directly to their Studio Lab projects. If you are sharing your notebook within a public GitHub repository, your content will be publicly readable. Do not share private content, such as AWS access keys or AWS Identity and Access Management credentials, in your notebook.

To add the functional **Open in Studio Lab** button to your Jupyter notebook or repository, add the following markdown to the top of your notebook or repository. 

```
[![Open In SageMaker Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/<PATH_TO_YOUR_NOTEBOOK_ON_GITHUB>)
```

## Import files from your computer
<a name="studio-lab-use-external-import"></a>

The following steps show how to import files from your computer to your Studio Lab project.  

1. Open the Studio Lab project runtime. 

1. Open the **File Browser** panel. 

1. In the actions bar of the **File Browser** panel, select the **Upload Files** button. 

1. Select the files that you want to upload from your local machine. 

1. Select **Open**. 



Alternatively, you can drag and drop files from your computer into the **File Browser** panel. 

## Connect to Amazon S3
<a name="studio-lab-use-external-s3"></a>

The AWS CLI enables AWS integration in your Studio Lab project. With this integration, you can pull resources from Amazon S3 to use with your Jupyter notebooks.

To use AWS CLI with Studio Lab, complete the following steps. For a notebook that outlines this integration, see [Using Studio Lab with AWS Resources](https://github.com/aws/studio-lab-examples/blob/main/connect-to-aws/Access_AWS_from_Studio_Lab.ipynb).

1. Install the AWS CLI following the steps in  [Installing or updating the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html). 

1. Configure your AWS credentials by following the steps in  [Quick setup](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html). The role for your AWS account must have permissions to access the Amazon S3 bucket that you are copying data from. 

1. From your Jupyter notebook, clone resources from the Amazon S3 bucket, as needed. The following command shows how to clone all resources from an Amazon S3 path to your project. For more information, see the [AWS CLI Command Reference](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/cp.html).

   ```
   !aws s3 cp s3://<BUCKET_NAME>/<PATH_TO_RESOURCES>/ <PROJECT_DESTINATION_PATH>/ --recursive
   ```

# Get notebook differences
<a name="studio-lab-use-diff"></a>

You can display the difference between the current notebook and the last checkpoint, or the last Git commit, using the Amazon SageMaker Studio Lab project UI.

**Topics**
+ [Get the difference between the last checkpoint](#studio-lab-use-diff-checkpoint)
+ [Get the difference between the last commit](#studio-lab-use-diff-git)

## Get the difference between the last checkpoint
<a name="studio-lab-use-diff-checkpoint"></a>

When you create a notebook, a hidden checkpoint file that matches the notebook is created. You can view changes between the notebook and the checkpoint file, or revert the notebook to match the checkpoint file.

To save the Studio Lab notebook and update the checkpoint file to match: Choose the **Save notebook and create checkpoint** icon (![\[Icon of a cloud with an arrow pointing upward, representing cloud upload functionality.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/Notebook_save.png)). This is located on the Studio Lab menu's left side. The keyboard shortcut for **Save notebook and create checkpoint** is `Ctrl + s`.

To view changes between the Studio Lab notebook and the checkpoint file: Choose the **Checkpoint diff** icon (![\[Camera icon representing image capture or photo functionality.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/Checkpoint_diff.png)), located in the center of the Studio Lab menu.

To revert the Studio Lab notebook to the checkpoint file: On the main Studio Lab menu, choose **File**, and then **Revert Notebook to Checkpoint**.

## Get the difference between the last commit
<a name="studio-lab-use-diff-git"></a>

If a notebook is opened from a Git repository, you can view the difference between the notebook and the last Git commit.

To view the changes in the notebook from the last Git commit: Choose the **Git diff** icon (![\[GitHub icon representing version control and source code management.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/Git_diff.png)) in the center of the notebook menu.

# Export an Amazon SageMaker Studio Lab environment to Amazon SageMaker Studio Classic
<a name="studio-lab-use-migrate"></a>

Amazon SageMaker Studio Classic offers many features for machine learning and deep learning work flows that are unavailable in Amazon SageMaker Studio Lab. This page shows how to migrate a Studio Lab environment to Studio Classic to take advantage of more compute capacity, storage, and features. However, you may want to familiarize yourself with Studio Classic's prebuilt containers, which are optimized for the full MLOP pipeline. For more information, see [Amazon SageMaker Studio Lab](studio-lab.md)

To migrate your Studio Lab environment to Studio Classic, you must first onboard to Studio Classic following the steps in [Amazon SageMaker AI domain overview](gs-studio-onboard.md). 

**Topics**
+ [Step 1: Export your Studio Lab conda environment](#studio-lab-use-migrate-step1)
+ [Step 2: Save your Studio Lab artifacts](#studio-lab-use-migrate-step2)
+ [Step 3: Import your Studio Lab artifacts to Studio Classic](#studio-lab-use-migrate-step3)
+ [Step 4: Install your Studio Lab conda environments in Studio Classic](#studio-lab-use-migrate-step4)

## Step 1: Export your Studio Lab conda environment
<a name="studio-lab-use-migrate-step1"></a>

You can export a conda environment and add libraries or packages to the environment by following the steps in [Manage your environment](studio-lab-use-manage.md). The following example demonstrates using the `default` environment to be exported to Studio Classic. 

1. Open the Studio Lab terminal by opening the **File Browser** panel (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/folder.png)), choose the plus (**\$1**) sign on the menu at the top of the file browser to open the **Launcher**, then choose **Terminal**. From the Studio Lab terminal, list the conda environments by running the following.

   ```
   conda env list
   ```

   This command outputs a list of the conda environments and their locations in the file system. When you onboard to Studio Lab, you automatically activate the `studiolab`  conda environment.

   ```
   # conda environments: #
              default                  /home/studio-lab-user/.conda/envs/default
              studiolab             *  /home/studio-lab-user/.conda/envs/studiolab
              studiolab-safemode       /opt/amazon/sagemaker/safemode-home/.conda/envs/studiolab-safemode
              base                     /opt/conda
   ```

   We recommend that you do not export the `studiolab`, `studiolab-safemode`, and `base` environments. These environments are not usable in Studio Classic for the following reasons: 
   +  `studiolab`: This sets up the JupyterLab environment for Studio Lab. Studio Lab runs a different major version of JupyterLab than Studio Classic, so it is not usable in Studio Classic. 
   +  `studiolab-safemode`: This also sets up the JupyterLab environment for Studio Lab. Studio Lab runs a different major version of JupyterLab than Studio Classic, so it is not usable in Studio Classic. 
   +  `base`: This environment comes with conda by default. The `base` environment in Studio Lab and the `base` environment in Studio Classic have incompatible versions of many packages. 

1. For the conda environment that you want to migrate to Studio Classic, first activate the conda environment. The `default` environment is then changed when new libraries are installed or removed from it. To get the exact state of the environment, export it into a YAML file using the command line. The following command lines export the default environment into a YAML file, creating a file called `myenv.yml`.

   ```
   conda activate default
   conda env export > ~/myenv.yml
   ```

## Step 2: Save your Studio Lab artifacts
<a name="studio-lab-use-migrate-step2"></a>

Now that you have saved your environment to a YAML file, you can move the environment file to any platform. 

------
#### [ Save to a local machine using Studio Lab GUI ]

**Note**  
Downloading a directory from the Studio Lab GUI by right-clicking on the directory is currently unavailable. If you wish to export a directory, please follow the steps using the **Save to Git repository** tab. 

One option is to save the environment onto your local machine. To do this, use the following procedure.

1. In Studio Lab, choose the **File Browser** icon (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/folder.png)) on the left menu, so that the **File Browser** panel shows on the left. 

1. Navigate to your user directory by choosing the file icon beneath the file search bar. 

1. Choose (right-click) the `myenv.yml` file and then choose **Download**. You can repeat this process for other files you want to import to Studio Classic. 

------
#### [ Save to a Git repository ]

Another option is to save your environment to a Git repository. This option uses GitHub as an example. These steps require a GitHub account and repository. For more information, visit [GitHub](https://github.com/). The following procedure shows how to synchronize your content with GitHub using the Studio Lab terminal. 

1. From the Studio Lab terminal, navigate to your user directory and make a new directory to contain the files you want to export. 

   ```
   cd ~
   mkdir <NEW_DIRECTORY_NAME>
   ```

1. After you create a new directory, copy any file or directory you want to export to `<NEW_DIRECTORY_NAME>`. 

   Copy a file using the following code format:

   ```
   cp <FILE_NAME> <NEW_DIRECTORY_NAME>
   ```

   For example, replace `<FILE_NAME>` with `myenv.yml`. 

   Copy any directory using the following code format:

   ```
   cp -r <DIRECTORY_NAME> <NEW_DIRECTORY_NAME>
   ```

   For example, replace `<DIRECTORY_NAME>` with any directory name in your user directory.

1. Navigate to the new directory and initialize the directory as a Git repository using the following command. For more information, see the [git-init documentation](https://git-scm.com/docs/git-init). 

   ```
   cd <NEW_DIRECTORY_NAME>
   git init
   ```

1. Using Git, add all relevant files and then commit your changes. 

   ```
   git add .
   git commit -m "<COMMIT_MESSAGE>"
   ```

   For example, replace `<COMMIT_MESSAGE>` with `Add Amazon SageMaker Studio Lab artifacts to GitHub repository to migrate to Amazon SageMaker Studio Classic `.

1. Push the commit to your remote repository. This repository has the format `https://github.com/<GITHUB_USERNAME>/ <REPOSITORY_NAME>.git` where `<GITHUB_USERNAME>` is your GitHub user name and the `<REPOSITORY_NAME>` is your remote repository name. Create a branch `<BRANCH_NAME>` to push the content to the GitHub repository.

   ```
   git branch -M <BRANCH_NAME>
   git remote add origin https://github.com/<GITHUB_USERNAME>/<REPOSITORY_NAME>.git
   git push -u origin <BRANCH_NAME>
   ```

------

## Step 3: Import your Studio Lab artifacts to Studio Classic
<a name="studio-lab-use-migrate-step3"></a>

The following procedure shows how to import artifacts to Studio Classic. The instructions on using Feature Store through the console depends on if you have enabled Studio or Studio Classic as your default experience. For information on accessing Studio Classic through the console, see [Launch Studio Classic if Studio is your default experience](studio-launch.md#studio-launch-console-updated).

From Studio Classic, you can import files from your local machine or from a Git repository. You can do this using the Studio Classic GUI or terminal. The following procedure uses the examples from [Step 2: Save your Studio Lab artifacts](#studio-lab-use-migrate-step2). 

------
#### [ Import using the Studio Classic GUI ]

If you saved the files to your local machine, you can import the files to Studio Classic using the following steps.

1. Open the **File Browser** panel (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/folder.png)) at the top left of Studio Classic. 

1. Choose the **Upload Files** icon (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/File_upload_squid.png)) on the menu at the top of the **File Browser** panel. 

1. Navigate to the file that you want to import, then choose **Open**. 

**Note**  
To import a directory into Studio Classic, first compress the directory on your local machine to a file. On a Mac, right-click the directory and choose **Compress "*<DIRECTORY\$1NAME>*"**. In Windows, right-click the directory and choose **Send to**, and then choose **Compressed (zipped) folder**. After the directory is compressed, import the compressed file using the preceding steps. Unzip the compressed file by navigating to the Studio Classic terminal and running the command `<DIRECTORY_NAME>.zip`. 

------
#### [ Import using a Git repository ]

This example provides two options for how to clone a GitHub repository into Studio Classic. You can use the Studio Classic GUI by choosing the **Git** (![\[Black square icon representing a placeholder or empty image.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/studio/icons/git.png)) tab on the left side of Studio Classic. Choose **Clone a Repository**, then paste your GitHub repository URL from [Step 2: Save your Studio Lab artifacts](#studio-lab-use-migrate-step2). Another option is to use the Studio Classic terminal by using the following procedure. 

1. Open the Studio Classic **Launcher**. For more information on opening the **Launcher**, see [Amazon SageMaker Studio Classic Launcher](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-launcher.html). 

1. In the **Launcher**, in the **Notebooks and compute resources** section, choose **Change environment**.

1. In Studio Classic, open the **Launcher**. To open the **Launcher**, choose **Amazon SageMaker Studio Classic** at the top-left corner of Studio Classic. 

   To learn about all the available ways to open the **Launcher**, see [Use the Amazon SageMaker Studio Classic Launcher](studio-launcher.md).

1. In the **Change environment** dialog, use the **Image** dropdown list to select the **Data Science** image and choose **Select**. This image comes with conda pre-installed. 

1. In the Studio Classic **Launcher**, choose **Open image terminal**.

1. From the image terminal, run the following command to clone your repository. This command creates a directory named after `<REPOSITORY_NAME>` in your Studio Classic instance and clones your artifacts in that repository.

   ```
   git clone https://github.com/<GITHUB_USERNAME>/<REPOSITORY_NAME>.git
   ```

------

## Step 4: Install your Studio Lab conda environments in Studio Classic
<a name="studio-lab-use-migrate-step4"></a>

You can now recreate your conda environment by using your YAML file in your Studio Classic instance. Open the Studio Classic **Launcher**. For more information on opening the **Launcher**, see [Amazon SageMaker Studio Classic Launcher](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-launcher.html). From the **Launcher**, choose **Open image terminal**. In the terminal navigate to the directory that contains the YAML file, then run the following commands. 

```
conda env create --file <ENVIRONMENT_NAME>.yml
conda activate <ENVIRONMENT_NAME>
```

After these commands are complete, you can select your environment as the kernel for your Studio Classic notebook instances. To view the available environment, run `conda env list`. To activate your environment, run `conda activate <ENVIRONMENT_NAME>`.



# Shut down Studio Lab resources
<a name="studio-lab-use-shutdown"></a>

You can view and shut down your running Amazon SageMaker Studio Lab resources from one location in your Studio Lab environment. The running resource types include terminals, and kernels. You can also shut down all resources of one resource type at the same time.

When you shut down all resources belonging to a resource type, the following occurs:
+ **KERNELS** – All kernels, notebooks, and consoles are shut down.
+ **TERMINALS** – All terminals are shut down.

**Shut down Studio Lab resources**

1. Start your Studio Lab project runtime. For more information on launching Studio Lab project runtime, see [Start your project runtime](studio-lab-manage-runtime.md#studio-lab-manage-runtime-start).

1. Choose the **Running Terminals and Kernels** icon (![\[Square icon with a white outline of a cloud on a dark blue background.\]](http://docs.aws.amazon.com/sagemaker/latest/dg/images/icons/Running_squid.png)) on the left navigation pane.

1. Choose the **X** symbol to the right of the resource you wish to shut down. You can view the **X** symbol by hovering your cursor over a resource.

1. (Optional) You can shut down all the resources of a given resource type by choosing **Shut Down All** to the right of the resource type name.