AWS Sagemaker for ML- Getting started with Sagemaker.

Spread the love

In this post, you will learn –

1 . Creating a AWS account

2 . Setting up additional Users and Roles

3 . Setting up AWS CLI

4 . Setting up AWS Sagemaker on your local machine.

5 . Setting up AWS Sagemaker Studio

1. Creating a AWS Account –

Go to and sign up for a new account.

Follow all the steps to create the account. Once done sign-in as a root user.

2. Setting up additional Users and Roles –

Your AWS root user is a special account that has full access to the account, and can perform all actions, including changing the payment methods, or closing the account. Due to this, it is recommended to not use your root account for day-to-day use, but instead create separate users for specific roles and functions. To set one up, you will first create an IAM User group – this will have a set of permissions that applies to any user that is part of the group.

Type IAM in the search box at the top center of the page, then click on IAM to start the process.

Click on User groups in the left side navigation, then on Create group. Enter the group name, e.g. “administrators”, then scroll down to Attach permissions policies. Search for “AdministratorAccess”, then check the box next to the policy with the name “AdministratorAccess”, scroll down and click on Create Group.

Next, create an IAM user by clicking on Users in the left side navigation bar, then clicking on Add user. After entering a username, you need to select the AWS access type. Programmatic access will create an access key ID and secret pair for use with the AWS CLI, CDK and other applications and the AWS Management Console access will allow the user to log into the AWS Console for this account. Select both of these options.

Click on Next to add the user to the group we created, select it from the list, then click on Next:Tags.

Tags are useful to search for resources across services, or to add metadata like department. For our use case, click on Next: Review without adding a tag. You can now review the values set for the user you are creating before actually creating it. You will notice there is an additional managed policy called “IAMUserChangePassword” added beneath the “administrators” one we created – this is added to any user where the option to force them to change their password was selected as not all IAM policies may have the required permissions in them.

Click on Create user to create the user. You will now see the confirmation screen for the user, but DO NOT click the Close button yet. The auto-generated password and the secret access key for API access can only be accessed from this screen once. Write down the Access key ID, Secret access key and Password – we will use them in the next module of this guide. You can also download it as a csv file. Afterwards, click on Close.

3. Setting up AWS CLI –

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts. To interact with AWS using the CLI, we need to configure credentials for it to use when making API calls.

Installing the AWS CLI –

There are different ways to install the AWS CLI, depending on your operating system, or preference to use containers. Please follow the latest guidance found here on how to install the AWS CLI v2. Once installed, you should be able to run aws –version and see the following output (version may be different):

aws --version
aws-cli/2.4.13 Python/3.8.8 Windows/10 exe/AMD64 prompt/off

Configuring AWS CLI credentials –

To configure the credentials, use the command aws configure and use the credentials that you created before. You will be asked for the AWS Access Key ID, AWS Secret Access Key, Default Region and Default Output Format

You should choose the region which is closest to you to reduce latency, minimize costs, or address regulatory requirements.

Note – Not all regions supports every sagemaker features. Like real-time predictions are only available in only us-east-1 and eu-west-1.

If you want, You can always specify or override the default region using the region flag (–region us-east-1) on any command. You can find a list of region codes here

Lastly, the format type is how the output should be displayed by default, and includes, but is not limited to: json, yaml, text. Once completed, you should see the following in the terminal (if you chose us-east-1 as your default region):

$ aws configure
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json

4. Setting up AWS Sagemaker on your local machine –

If you want to use aws sagemaker locally on your computer to train and deploy your models, you can also do that.

To avoid dependency conflict, we will install it using a virtual environment.

Installing Sagemaker SDK using Anaconda –

1 . First create and activate the sagemaker environment.

conda create --name sagemaker
conda activate sagemaker

2 . Then, we need to install pandas, boto3 and the sagemaker SDK. The sagemaker SDK has to installed using pip as it is not available as a conda package.

conda install boto3 pandas
pip install sagemaker

3 . Next, we need to install jupyter notebook and add it’s dependencies to the environment that we created.

conda install jupyter
python -m ipykernel install --user --name=sagemaker

4 . Then launch jupyter notebook.

jupyter notebook

You can see the new sagemaker kernel when you create a new notebook.

5 . Test the installation.

Click on New and then sagemaker to create a new notebook. Then type the following commands to make sure that everything is working properly.

import boto3
import sagemaker


6 . Deactivate virtual environment.

Once you are done working with your projects, first close the jupyter notebook and then deactivate the virtual environment.

conda deactivate sagemaker

5 . Setting up AWS Sagemaker Studio –

Now, let’s setup AWS sagemaker studio on AWS. Sagemaker studio let’s you build, train and deploy ML models on AWS. You can create jupyter notebooks, upload data, train and tune ml models, track their progress and all kinds of other ML works using Sagemaker Studio.

First, open Amazon sagemaker by typing it in the search bar at the top.

Then click on Sagemaker studio at right or in left navigation. This will open up the setup page.

Here, provide a user name and from the drop down menu create a new execution role.


Here, select Any s3 bucket and click on create role. This will bring you back to the previous page.

Now, click on submit. This will start the on boarding process. Please wait for sometime to finish the process. Once finished you will see the confirmation message that account is ready.

Now, click on Launch app to launch sagemaker studio. After sometime you will see a fully functional JupyterLab to perform all kinds of ML tasks.

To create a new notebook, click on file > notebook and then select data science image and python 3 as shown below. Then click on select.

Now, you can run your code in the notebook.

To know which resources are being used click on the left navigation.

Once, you are finished with your work, shutdown all the resources to avoid unnecessary charges. Click on File > shutdown > shutdown All.

Rating: 1 out of 5.

Leave a Reply