Configure Jupyter Notebook on AWS in Two Steps

Purnendu Last Updated : 19 May, 2022
6 min read

This article was published as a part of the Data Science Blogathon.

Introduction

Let’s You have a job crunching trillions of image data points to extract insights, and you don’t have sufficient storage or processing power to do it, so what will you do – Stop in the Middle or Get a system with Some Storage and Compute Power?

Well, if your answer is the second one, then you have a solution called cloud computing, and AWS (Amazon Web Services) is the best way to go due to the numerous features it provides:

  • Cloud-based – No hardware is required from your end.
  • Accessible – Your can be accessed from anywhere around the world.
  • No Maintainance – You don’t need to worry about the machine (storage & Compute Power) you own.
  • High Security – Your data, project, product, and system are in safe & trustworthy hands.
  • Variability – Multiple systems can be used.
  • Price Friendly – As everything has cost included, this too has, but it’s minimal compared to buying the local one. Thanks to AWS pricing strategies.

So to summarise, even if you are doing what you want in some claimed machine, you don’t need to worry about security, computing, storage, and managing the device. You can also access it.

In Today’s article, we will discuss how you can set up your next jupyter instance on AWS  for heavy data workloads.   and later look into ways to be smart with AWS and end with some don’ts while using AWS. Overall, it will be a hands-on and fun-packed journey to travel.  So let’s move on to the more practical side that any enthusiastic DS aspirant wants!

Set Up & Launch Instance

Instances are the VMs provided by AWS for usage. Each one has some user-defined – Type, OS, Storage, Networking, and Security.  So now, let’s look practically at how each piece fits together!

Imp: Visit the AWS login page and log in to your account; click signup, fill in the required details, and verify to get a new profile with free tier eligibility.

1. Log in to your account, and in the console search bar, type EC2 and click it (The Elastic Cloud – Sevice).

Set Up & Launch Instance 1

 

2. Once in the instance window, select  Launch Instance.

Set Up & Launch Instance 2

3. In the new window, fill in all the required details as follows:

  • Name & Tags – Name your machine.
  • Os Image & Architecture – Select operating system and CPU architecture – make sure it’s in the free tier.
  • Instance Type – Use t2.micro -720 hrs of free usage every month for 1 year.
  • Key pair – Add a pivotal name to create a private key and download it.
  • Network Setting – Add Custom TCP port as 8.8.8.8 and Sources -> Anywhere by going to Edit
  •  Storage – Select up to 30 Gb for the free tier. – Keep default.
  • No Of Instances – Set as 1 / as you need.

Finally, launch the instance.

Set Up & Launch Instance 3

4. Once the launch is complete, go to View all instances on the next page and then check the status if it says check passed 2/2:

Set Up & Launch Instance 4

Result:

5. Finally, navigate to the folder you downloaded crucial and open the terminal. Select instance type, click Connect and go to SSH Client in the above. Now copy the code in the airport and press enter.

ssh -i "ubuntu_instance1.pem" [email protected]

Here “ubuntu_instance1.pem” is the key we downloaded. For mac, it’s a cer file.

The result looks like this: for windows.

So congrats, you have now your machine. Lets’s currently set up our notebook in the next section.

Installing  Notebook

Note: – I have changed the instance (refer to command line😅) as there were some issues with the old one, but all process remains the same. 

This section covers installing the jupyter-notebook, but the same process can be followed to add any dependency you may require for the job.

1. Before anything, update your environment packages – a safe check :

sudo apt update
sudo apt-get update

2. Once everything is sorted, add the below command to install the package using apt :

sudo apt install jupyter-notebook
install jupyter-notebook
install jupyter-notebook 2

3. Now open the notebook by calling:

jupyter notebook -ip 0.0.0.0 --no-browser
jupyter notebook

4. Now comes the most essential part – copy the given URL and replace it as:

 http://127.0.0.1:8888/?token=a3e3b3aef98cfbb6159efd4a31a090d971a9611c5380952f

to

 http://[Publicic IPv4 Address]:8888/?token=a3e3b3aef98cfbb6159efd4a31a090d971a9611c5380952f

in this case – 15.206.195.91. You can find it by selecting instances -> Details -> Public IPV4 addresses.

Output

JUPYTER Output

Congo, you have successfully launched a jupyter notebook on AWS, and it was this easy!.

Working Smart With AMI

If you want to replicate your work with the same settings, you need to create new instances, which can be a tedious task and error-prone. So let’s be smart here and use AMI – Amazon Machine Image.

AMIs are just copies of your machine and have the same OS, Storage, Memory, process, Networking, and security configuration. Although its also allowed to change them as per convenience.

Here is how you can create AMI :

1. Head to the EC2 instance page and select Actions -> Image & templates -> Create image 

Amazon Machine Image 1

2. Enter:

  •  Image Name –  Name of the image, personal choice.
  • Description – About the image -> can include details of what instances copy has.
  • No RebootEnable to save the booting time as amazon will not remove the instances files after shutdown.
  • Add volume – Add extra storage if necessary.
  • Tags – Just for reference (optional).
Amazon Machine Image 2

3. Now, finally click Create image button, and you are done:

Amazon Machine Image 3

Image By Author

Once done, you can select the AMI from Launch Instance -> My AMI’s Section and follow along from Setup & Launch Instances section:

Reference Image:

Amazon Machine Image 4

Conclusion

Although we have barely scratched the surface of AWS, using the method discussed, you can enhance your productivity by a lot. Here is a brief summary of whatever we have covered:  

  • Intro: We learned about AWS, its benefits for our use cases, and the factors affecting it.
  • Launching Instances: Here, we learned how one can easily configure their own machine and find them within minutes or two. We also learnt to perform SSH using our own local machine and its requirements.
  • Adding Dependencies: The important core part here was how to update and install packages on Linux.
  • AMI’s: This section covered a more innovative way to create multiple instances with the same configuration.
  • As for the final part – we learned you should permanently close your instances whenever not required. Else, you may get a hefty bill.

There are more services than discussed here. I hope you explore other services like AWS Lightsail, Lambda, VPC, Batch, Outposts, etc. 

So this concludes today’s article, and I hope you have learned something and planning to apply it. You can share your suggestions & issues in the comments. Also, feel free to reach me on my LinkedIn, Twitter, and Github.

Finally, if this read added some value, consider sharing with others as sharing is caring!.

The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

A dynamic and enthusiastic individual with a proven track record of delivering high-quality content around Data Science, Machine Learning, Deep Learning, Web 3.0, and Programming in general.

Here are a few of my notable achievements👇

🏆 3X times Analytics Vidhya Blogathon Winner under guides category.

🏆 Stackathon by Winner Under Circle API Usage Category - My Detailed Guide

🏆 Google TensorFlow Developer ( for deep learning) and Contributor to Open Source

🏆 A Part Time Youtuber - Programing Related content coming every week!

Feel free to contact me if you wanna have a conversation on Data Science, AI Ethics & Web 3 / share some opportunities.

Responses From Readers

Clear

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details