Automate AWS EC2 Setup: Launch Jupyter Notebook with Python & Boto3
Key Takeaways
This video demonstrates how to automate AWS EC2 setup using Python and Boto3, launching a Jupyter Notebook environment and configuring AWS credentials with required permissions. It covers the programmatic way to launch an Amazon EC2 instance, set up a Jupyter Notebook environment, and interact with AWS services using Boto3.
Full Transcript
So now we are going to proceed with our next step. So for that I'm going to open my command prompt in the local setup. So I'll be pressing window r and I'm going to open the command prompt everybody. Now the thing is you should be having the Jupiter notebook setup ready in your local okay or you can say that in your command prompt you have already configured the AWS credentials and you are having your setup ready because what exactly we're going to do as I told you in this particular part I'm going to show you like how using the Jupyter notebook in the local we are going to set up an EC2 instance in the AWS account and do the required installation. Okay. So again I can quickly check Python space-en version. Okay. And I have already configured AWS credentials. I had shown you in my past videos that how to configure AWS credentials with the required permissions. So either for the practice purpose you can configure the credentials with the administrator privileges and once your demo is done deactivate the access keys or the other way is you can give the required access which is used to perform this particular demonstration. For example in this demo I want to launch an EC2 instance. Okay. So I have already provided the enough access in order to perform this demo. So how I'm going to start my Jupyter notebook in the local I will be typing here Jupiter notebook and let's see what I'm going to get after typing Jupyter notebook. It should be running Jupyter notebook and I will be getting a prompt in the browser that is going to load a notebook in my local machine. You can see the response from here. It is saying that extension manager is this. And here you can see it has opened a Jupyter notebook in my local machine. Everybody, this is my local browser. You can also relate it from local host. Now what you have to do, you can open a new notebook if you want. Okay. And you can also explore all these things like you have Python that is a kernel. This is a terminal. This is console and many more things you can explore from here. Okay. You can go to file. I'm going to open a new notebook everybody here. And then this is my script. Now I'm going to give you a highlevel idea what the script is doing. First of all, we are importing the required libraries. Let me do that. So you can take it step by step even. So import the required libraries. You can run this. Once this is executed successfully, the next step is I'm going to provide a set of parameters. Now, now the region name is the name where you are going to launch an EC2 instance. So, for example, I am providing the region name as AP South one because I will be launching the EC2 instance in Mumbai region. Okay, those who are new to AWS, they can always take the region code from the top means right now I'm talking about Asia Pacific Mumbai which is having a region code as AP- South. So I've taken this code from here. Okay. So this code has been taken. Now next thing is we have to provide the AMI. What AMI is? I told you AMI stands for Amazon machine image. Now AMI is a region specific means each region would be having the different AMIs with the AMI ids. When I'm talking about different AMIs here I'm specifically mentioning the AMI ids. Okay. So I will be needing an AMI ID here. How can I get it? For example, if I have to launch an Ubuntu instance in the AP South one which is a Mumbai region. Okay, I'll be choosing the AMI ID. How? Let's go to instances. I'm just clicking on launch instance this time to take the AMI ID. So from where you can get the AMI ID in this section once this Amazon machine image section would be loaded I will be copying the AMI ID for Ubuntu AMI okay let's select this and scrolling down from here you can take the AMI ID let me make a copy of it and I'll be pasting it here okay then instance type would be the one which you want to launch. So in my case I'm launching an instance of type T3.m medium but I told you use the one which you want to basically launch as a part of free tier and then key name is basically a key pair which will be used to connect to this EC2 instance externally using remote client. Obviously I'll not be doing that. If I would be required to troubleshoot something, I would be using EC2 instance connect. But here I have to provide the one which is existing in my account. If you are new to it, go back and expand these horizontal lines. If you scroll down here, you can see under network and security, we have key pairs. Go to key pairs and let's create a new key pair everybody. So let's say Jupiter keeper something like this keep rest all settings default just copy this name and we're going to use this name as a part of our code okay so no need to worry about if you don't have any key pair existing in your account just create a new in the way I have told you this is the connection which we are establishing using boto3 which is basically a SDK for python account. This particular instruction is helping me out to get my IP which I will be adding in the security group rules. Okay. And here I'm providing a security group name. So let's say if this security group would already be existing in my account when I am going to execute this piece of code, it will be saying security group already exist. So let me give it another name called Jupiter security group new. Okay. Restore settings. What we will be doing? We will be creating a security group. This is the first thing. We are allowing some rules on port 22 and this port 8888 means whatever you had done from the management console now we are doing it using code. And finally we are passing a user data. This user data is doing the same thing which you had done using commands like installing the python pip or virtual environment configuring the environment and providing certain properties and finally it is starting Jupyter notebook. Okay. So when I would be running this EC2 instance this particular user data script would be running at the time of launch. Okay. And finally after waiting for some time I will be connecting to the Jupyter notebook here. Okay let's do it. Let me quickly take this particular piece of code everybody. You can go through it if you want. I have given you a highle idea what exactly I'm doing from here. Okay. So we're starting from defining some parameters which will be required to launch an EC2 instance. We are creating an EC2 object using BTO3 client. We are fetching the IP address. This is the my IP address. In your case, it will be your IP address which is provided to you by your internet provider. Okay. This is a security group name. This is a security group description. The first thing we are doing, we are creating a security group. Later we are aligning some rules and the traffic we are aligning from my IP address. the one which we had fetched in the above part of our code. If there would be some error, we are going to throw some exceptions. Okay, this is a user data. This is to install and run the Jupiter. So, all the prerequisite which will be used, we are doing it from here. Finally, we are calling the run instance method and we are passing all the required things. We are printing the instance ID. We are waiting for the instance to come up and running. We are fetching the public IP address. And once the public IP address is fetched, we can access our Jupyter notebook using http/ublic IP888. Okay. And we have to wait for certain time in order to get our Jupyter notebook ready. This would be happen because we are passing a user data script which I told you will be running at the time of launch. Let's run this piece of code and let's see what happens. You can see the response here. Let's wait for the response to get. It is detecting my IP address. It's creating a security group. Launching the instance. Waiting for instance to run. Instance is running. And now I can access Jupyter notebook after 2 3 minutes. The first thing you all can see here how faster it was. So it's your choice. Do you want to launch an EC2 instance using management console or do you want to launch it programmatically? So you have both the ways. Whatever you prefer, whatever you want, you can follow the same set of instruction. Let me click here and let's see what I'm going to get after couple of minutes. In the meantime, I can quickly give you a brief summary what we have done here. We started with launching an EC2 instance using Ubuntu image and then we basically chosen the instance type and all the required properties for launching an EC2 instance. Once done, we connected to our EC2 instance. did the required configuration in terms of installing certain packages, setting up virtual environment, manage the configurations, allow the rules and finally we had access the Jupyter notebook in the browser after providing the I password at the login page. Okay, later I told you how can you do the same thing programmatically. How can you write a piece of code and using that piece of code you can achieve the same result. Okay. So let's quickly wait and we will be seeing a Jupyter notebook. So we'll be waiting till the time I'm going to get the access to Jupyter notebook and once it is done we are going to conclude this particular part of our discussion. So you can see here your Jupyter notebook is running in the browser and you can do the same thing if you have to install some additional packages you can open the terminal and again you can install the additional packages in a similar manner. Okay. So this is something I wanted to show you. So you can see this was a Jupyter notebook running. This was a Jupyter notebook running in my local machine. And again this was a one which was running from a past EC2 instance which we had launched using management console. Okay. So this is something I wanted to show you and I hope you can find it interesting and you can gaze an understanding how can you continue your journey in cloud on whatever role you are into.
Original Description
Take your cloud skills to the next level by learning how to automate your infrastructure! In this tutorial, we demonstrate the programmatic way to launch an Amazon EC2 instance and set up a Jupyter Notebook environment using Python and the Boto3 SDK.
Moving beyond the manual management console, we show you how to write a script that provisions your server, configures security, and installs all necessary software automatically.
In this video, you will learn:
✅ How to configure AWS credentials and use the Boto3 library in a local Jupyter environment.
✅ How to dynamically fetch your local IP address to automate Security Group rules.
✅ Setting up Security Groups for SSH (Port 22) and Jupyter (Port 8888) via code.
✅ Using EC2 User Data to automate the installation of Python, Pip, and Jupyter Notebook at launch.
✅ Fetching the Public IP of a newly created instance to access your remote notebook instantly.
✅ A comparison between Manual Console Setup vs. Programmatic Automation.
This method is essential for Data Scientists and DevOps engineers who want to build reproducible, "Infrastructure as Code" environments.
Resources Mentioned:
- AWS SDK for Python (Boto3)
- Ubuntu AMI IDs
- EC2 Instance Types (T3.medium/T2.micro)
#AWS #Boto3 #Python #JupyterNotebook #Automation #EC2 #CloudComputing #InfrastructureAsCode #DataScience #AWSAutomation
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Analytics Vidhya · Analytics Vidhya · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
The DataHour: Data Science in Retail
Analytics Vidhya
The DataHour: Anomaly detection using NLP and Predictive Modeling
Analytics Vidhya
The DataHour: Energy Data Science Project from Scratch
Analytics Vidhya
The DataHour: Explainable AI Need and Implementation
Analytics Vidhya
The DataHour: Google Cloud AI/ML
Analytics Vidhya
Prediction to Production in Machine Learning #machinelearning #prediction
Analytics Vidhya
Practical Applications of Data science in Ecommerce
Analytics Vidhya
How to tackle Overfitting?#machinelearning #overfitting
Analytics Vidhya
Building Data Pipelines on GCP #googlecloud #datapipelines #data
Analytics Vidhya
Hands-on with A/B Testing #abtesting #datascience
Analytics Vidhya
Efficient Implementations of Transformers #transformers #cnn #machinelearning
Analytics Vidhya
Modern Deep Learning Architecture #deeplearning #architecture #deeplearningtutorial
Analytics Vidhya
Key steps for Designing Artificial Neural Network (ANN) for Image classification #machinelearning
Analytics Vidhya
5 things you should know about Azure SQL #azure #sql #datahour #datascience
Analytics Vidhya
AI & ML in the Automotive Industry #machinelearning #ai
Analytics Vidhya
Building Machine Learning Models in BigQuery
Analytics Vidhya
NLP aspects in Telecommunication Industry
Analytics Vidhya
Practical Time Series Analysis
Analytics Vidhya
Fundamentals of Quantum Computing
Analytics Vidhya
A DAY IN THE LIFE of a Data Scientist (From waking up to working on algorithms)
Analytics Vidhya
Classification Machine Learning Model from Scratch
Analytics Vidhya
Knowledge Graph Solutions using Neo4j
Analytics Vidhya
Model Guesstimation (MLOps)
Analytics Vidhya
ETL Pipelines in Google Cloud Platform
Analytics Vidhya
Key steps for Designing Convolutional Neural Network(CNN) for Image Classification
Analytics Vidhya
Getting Started with AWS EC2 #amazon #aws
Analytics Vidhya
How to Use Azure NLP and Graph Databases for Intelligent Knowledge Mining
Analytics Vidhya
Certified AI & ML BlackBelt Plus Program #shorts
Analytics Vidhya
Visualizing Data using Python #machinelearning #visualization #python
Analytics Vidhya
DCNN for Machine RUL Prediction using Time-series Data #timeseries #machinelearning #datascience
Analytics Vidhya
M in ML stands for Math & Magic
Analytics Vidhya
An Unsupervised ML approach using Clustering
Analytics Vidhya
Customizing Large Language Models GPT3 for Real-life Use Cases #gpt3 #datascience
Analytics Vidhya
Model Parameters vs Hyperparameters - Techniques in ML Engineering #machinelearning
Analytics Vidhya
Practical MLOps #mlops #datascience
Analytics Vidhya
Data Engineering with Databricks #dataengineering #databricks
Analytics Vidhya
Multi-Objective Optimisation
Analytics Vidhya
When Airflow Meets Kubernetes
Analytics Vidhya
AI in Banking
Analytics Vidhya
Learn Convolutional Neural Network for Image Recognition
Analytics Vidhya
Extracting Value from Data
Analytics Vidhya
How to measure Marketing Channel Effectiveness
Analytics Vidhya
Transforming Lives | Data Science Immersive Bootcamp
Analytics Vidhya
Stock Market Analysis - AI driven approach
Analytics Vidhya
Become a Data Engineering Professional in 2022 | Future Trends + Skills Required
Analytics Vidhya
Ensemble Techniques in Machine Learning #machinelearning #ensemble #datascience
Analytics Vidhya
The Power of Visualization | Tableau Full Course | Analytics Vidhya
Analytics Vidhya
Demand for Data Engineers is on the Rise | Data Engineer | Analytics Vidhya
Analytics Vidhya
Data Visualization in Data Science | DataHour | Analytics Vidhya
Analytics Vidhya
Role of Optimization in Machine Learning & Deep Learning | DataHour | Analytics Vidhya
Analytics Vidhya
Solving any Machine Learning Problem | Approach and Steps Involved
Analytics Vidhya
Topic Modeling Explained with Implementation | Using LDA in Python | DataHour by Arpendu Ganguly
Analytics Vidhya
Data Engineering in E-Commerce | The Best Case Study
Analytics Vidhya
Introduction to Classification using Azure Machine Learning | DataHour | Analytics Vidhya
Analytics Vidhya
Introduction to Federated Learning | DataHour | Analytics Vidhya
Analytics Vidhya
Diffusion Models for Generative Arts | DataHour | Analytics Vidhya
Analytics Vidhya
Master Google Analytics in 1 Hour | DataHour | Analytics Vidhya
Analytics Vidhya
Learn Hypothesis Testing | DataHour | Analytics Vidhya
Analytics Vidhya
A Practical Approach to Kaggle Competition | DataHour | Analytics Vidhya
Analytics Vidhya
Making AI work for Business | DataHour | Analytics Vidhya
Analytics Vidhya
More on: AI Systems Design
View skill →Related Reads
📰
📰
📰
📰
Boost Your Terminal Productivity: 10 Essential Tips
Dev.to · Binary Journal
R&D su un Database di Security 100% Statico: GitHub Actions, Hugo e Zero Backend
Medium · DevOps
Do Not Invent a 5-Hour Window in a Codex Usage Tracker
Dev.to · Agent Island
How to Create a Linux Virtual Machine on Azure (Step-by-Step for Beginners)
Dev.to · SULIAT
🎓
Tutor Explanation
DeepCamp AI