Writing

Exploring Amazon SageMaker AI

14 January 2018Updated 14 October 20264 min read

A walkthrough of Amazon SageMaker AI, the AWS service for building, training and deploying machine learning models. We set up a SageMaker AI domain, open a JupyterLab space in SageMaker Studio and run TensorFlow and SageMaker Python SDK code.

Amazon SageMaker AI is a fully managed cloud service for building, training and deploying machine learning models. AWS renamed the service from Amazon SageMaker to Amazon SageMaker AI in December 2024. AWS now uses the name Amazon SageMaker for a wider data, analytics and AI platform, and SageMaker AI is the machine learning part of it. SageMaker AI manages the infrastructure, so data science teams can focus on building models. It also provides built-in algorithms and pre-trained models to speed up building, training and deploying models.

The main place to work in SageMaker AI is Amazon SageMaker Studio, a web-based environment with several development tools, including JupyterLab and Code Editor. JupyterLab in Studio uses the SageMaker Distribution image by default. The image includes popular libraries such as PyTorch, TensorFlow, Keras, NumPy, pandas and scikit-learn. You can keep your data in Amazon S3, the AWS object storage service, and read it from your notebooks. SageMaker AI also offers notebook instances, which run the Jupyter Notebook application on a single ML compute instance. This walkthrough uses Studio.

In this tutorial, we'll walk you through getting started with SageMaker AI. To begin, sign in to the SageMaker AI console. If you do not have an AWS account, create one before proceeding.

Set Up a SageMaker AI Domain

Studio runs inside a SageMaker AI domain. A domain holds user profiles and their settings. For a single user, the quickest path is Quick setup:

  1. Open the SageMaker AI console and open the left navigation pane.
  2. Under Admin configurations, choose Domains.
  3. Choose Create domain.
  4. Choose Set up for single user (Quick setup).

Quick setup creates the domain and a user profile with default settings. It also creates an IAM execution role with the AmazonSageMakerFullAccess policy attached. The notebooks and jobs you run in Studio use this role to access other AWS services.

Store Your Data in Amazon S3

We need a storage location for the data that trains and evaluates the model. SageMaker AI also needs a bucket to store training output and model artifacts. Quick setup creates an S3 bucket for you with a name that starts with sagemaker-studio-.

If you create your own bucket in the Amazon S3 console, put the word sagemaker in its name. The AmazonSageMakerFullAccess policy allows reading and writing objects in buckets whose names contain sagemaker, Sagemaker or SageMaker. The Quick setup role also has the AmazonS3FullAccess policy. The naming rule matters when you use a role that relies on AmazonSageMakerFullAccess alone.

Open SageMaker Studio

  1. In the SageMaker AI console, choose Studio from the left navigation pane.
  2. Select the domain and user profile that Quick setup created.
  3. Choose Open Studio.

Create a JupyterLab Space

A JupyterLab space manages the storage and compute that the JupyterLab application runs on. To create one:

  1. In Studio, choose JupyterLab.
  2. Choose Create JupyterLab space.
  3. Enter a name for the space and choose Create space.
  4. Under Instance, you can choose the Amazon EC2 instance type that runs the space. We keep the default for this tutorial.
  5. Choose Run space.
  6. When the space is running, choose Open JupyterLab.

The space runs on a single EC2 instance with an Amazon EBS volume for storage. You can switch to a faster instance or increase the volume size later. Stop the space when you finish so that the instance does not keep running.

Run TensorFlow Code

Let's create a new notebook and run some TensorFlow code to check that everything works. Open a new Python 3 notebook from the JupyterLab Launcher and run:

python
import tensorflow as tf print(tf.__version__) a = tf.constant(2) b = tf.constant(3) c = a + b print(c.numpy())

The last line prints 5. TensorFlow 2 runs operations eagerly, so c holds the result as soon as the line runs. c.numpy() returns that result as a NumPy value.

Check the SageMaker Python SDK

The SageMaker Python SDK is the library we use to train and deploy models from a notebook. Version 3 of the SDK is split into packages such as sagemaker-core, sagemaker-train and sagemaker-serve. At the time of writing, the latest release is 3.25.0. Check which version your space has:

python
%pip show sagemaker

If the output shows a 2.x version, upgrade the SDK and then restart the kernel:

python
%pip install --upgrade sagemaker

Now create a session and look up the execution role and the default S3 bucket:

python
from sagemaker.core.helper.session_helper import Session, get_execution_role session = Session() role = get_execution_role() print(f"Using role: {role}") print(f"Default bucket: {session.default_bucket()}")

The output shows the IAM role that your notebook runs as and the S3 bucket that the SDK uses by default.

So there you have it. You now have a managed JupyterLab environment on SageMaker AI, with TensorFlow and the SageMaker Python SDK ready to use. From here, you can train models with SageMaker AI training jobs and deploy them to SageMaker AI endpoints.

Ekaba Bisong is a Ph.D. researcher at the University of Victoria and the founder of SiliconBlast. More about me