AWS for Data Science: EC2 vs. SageMaker vs. Lambda - The Ultimate Guide (with Demos)(3/4)

Analytics Vidhya · Beginner ·☁️ DevOps & Cloud ·8mo ago

Key Takeaways

This video provides a comprehensive guide to choosing the right AWS service for machine learning projects, including EC2, SageMaker, and Lambda, with demos and step-by-step instructions.

Full Transcript

Hello everyone. I welcome you all as a part of this particular video lecture where we are going to explore compute for data science. And this video lecture is based out on EC2 versus Sage Maker versus Lambda for data science task. Now before I'm going to get deep dive into this video lecture, let me put one statement in front of you and that is servers are everywhere. Means whatever task we are doing, whatever things we are performing, we will be needing server or we can say that we will be needing compute power. Now our journey is to provision the server where we are looking for more control to the flexibility where AWS or any cloud provider is going to manage the things for you and in this journey only we will be discussing EC2 SageMaker and Lambda. Now before you are going to talk about these services there are two pointers you always need to understand what and why means what is EC2 sage maker or lambda and second thread which you have to talk about that is why EC2 sage maker and lambda and if you want to understand in a more detailed manner you can also get an answer to one more question that is where EC2 sage maker and lambda now best place to start about any AWS service is the AWS management console or the AWS documentation. So I'm assuming that till the time all of you would be having an active AWS account and if you all have an active AWS account. So without any further delay let's move towards your AWS account. So I'm navigating to my AWS account. This is a landing page everybody and you know how can you search for a particular service in the AWS search bar. So either you can type the name of the service like I'm typing here and when you are typing the name you will be getting a very short description about a service let's say virtual servers in the cloud means this service is helping you out in order to provide guest machines or virtual machines in the cloud and the best part is it will also be giving you some top features in a similar manner you can search for lambda here also you can see run code without thinking about servers means we will be putting Lambda into serverless categories and finally you can search for Sage Maker. Sage maker is the center for data analytics and AI. Also, if you want to put the service into specific category, you can explore the categories from here. Let's say you can explore the category called analytics. In a similar manner, you can explore the category called compute. So, Sage Maker comes under analytics category. From the definition I have get an idea into. In a similar manner, if you will be going to compute, you will be seeing EC2 and lambda. Okay. Now, this was a short description about Lambda, EC2 and SageMaker. Let me give you a quick overview one more time. So, EC2 stands for elastic compute cloud which gives you virtual servers you manage completely. So here I have put one pointer in front of you that is management is on you. When management is on you it means control is with you. Okay. So here our choice is control. Our choice is management means you can choose the instance type. You can decide what is a specification of your virtual machine you need. You can choose the operating system. You can choose the libraries or other prerequisite. So EC2 is best for full control custom environments longunning or high performance compute workload. Now remember these keywords the highlevel keywords which I have presented in front of you and if you are aware about these keywords you will be able to relate that for this particular use case this service is a best friend. In a similar manner when we talk about lambda a simple definition for lambda you can give lambda provides you eventdriven serverless compute option. Now serverless means that you don't have to gain visibility into underlying infrastructure or you don't have to worry about underlying infrastructure. Just focus on your code and AWS is going to take care about rest of the things for you. Means you can say lambda provides you serverless functions that run code in response to events with short execution time. So what lambda is best for? So lambda is best for lightweight eventdriven data processing or inference. And the last service I will be talking about that is Sage Maker. So SageMaker is a fully managed service for building, training and deploying machine learning models. So Sage Maker is providing you a best fit for end to end ML workflows where you are talking about data preparation, training, deployment with less operations overhead. So what journey we are talking about here? So we're talking about our journey starting from control to the less management to the more flexibility means here we are talking about these services in terms of what these services are best fit for. Okay. Now whenever you are planning to use any service you always need to understand certain pointers. Let's say if I'm talking about compute model and cost. So in terms of compute control if I'm just taking this as a feature in EC2 you will be having a full control means you can choose the things based on your need based on your choice but always remember when you're talking about full control the management would be more at your side. Okay. So accordingly you have to decide accordingly you have to make a choice. In SageMaker as it is a managed service you can choose the instance type but AWS is going to handle the setup and scaling and for lambda there is no servers means AWS will be allocating the runtime automatically underlying infrastructure would be there when I'm using a word no servers it means you don't have visibility into the underlying infrastructure like how AWS is provisioning the resources for you where the actual execution will happen. Okay, always understand the billing. That is a very important part because even if you are from a development background, okay, at a certain point of time, you should be having a little bit understanding on pricing. Let's say if you're a part of a call with your stakeholders, then you need to present that why you are using this particular service. So if I talk about a billing model, EC2 follows a billing model called pay per second. Means while instance is running, you have to pay the charges per second. If I talk about Sage Maker, Sage Maker follows a billing model where you are paying for a time used for training inference and also the idle notebooks cost money. For Lambda, you are paying per request and compute time. In a similar manner if I'm talking about scalability so scalability in case of EC2 can be manual or you can also scale your infra via autoscaling group Sage Maker provides you built-in autoscaling for training and inference means you can choose the instance type you have that much of flexibility but setup will be taken care by AWS for you and also it will be the same thing with the scaling part Lambda provides you automatic scaling for event trigger. Okay. So you have got a basic understanding on these services like what are the use cases where these services are best fit for. Now understand the use cases for data science. If I'm just putting a subject in front of you, we have to understand the use cases from that subject perspective. Let's say if I am talking about different options in our data journey. The first option where we are talking about data exploration and notebook work. Okay. If you have to explore the best AWS options or best AWS services for this particular use case, you can say that use a combination of Sage Maker Studio on EC2 plus Jupiter. Okay. Means Sage Maker gives manage notebook. EC2 gives you flexibility. If you're talking about feature engineering or ETL, extract transform load, lambda you can use for eventdriven small jobs, EC2 and SageMaker you can use for processing jobs. If you are talking about model training stage there you can make use of Sage Maker training jobs or EC2 custom means Sage Maker handles the distributed training hyperparameter tuning and spot instances management. If you're talking about the next stage which is model deployment you can make use of SageMaker endpoint lambda or EC2. In a similar manner for batch predictions you can make use of SageMaker batch transform or EC2 and finally if you are having some eventdriven ML means let's say if you're talking about realtime classification lambda is a best choice for you. So this is something where we are talking about the use cases for data science. Don't worry soon I will be presenting some example scenarios in front of you. Okay. But before that the next thing which we are going to talk about that is maintenance and management. Okay. This is a very important part. Although we have already got a very good understanding with respect to control and flexibility but let's understand different aspect for example if I'm talking about infra management everybody [laughter] in case of EC2 you manage everything manage everything means on top of virtual machines in case of sage maker AWS manage almost everything and in case of lambda you don't have to worry about underlying infrastructure at all. Second thing if I talk about that is environment setup that is the next aspect which you have to understand. So in case of EC2 environment setup is manual in case of sage maker you have pre-built environments like you have tensorflow you can have py talk okay you can have skarn in case of lambda it's lightweight means you can bring your code plus dependencies if I talk about monitoring and logging which is a very important aspect for any particular service so in case of EC2 you have cloudatch but you need to do a manual setup. In case of SageMaker, you have integration with Cloudatch and also you have a feature of SageMaker called SageMaker Studio. In Lambda, you can make use of the Cloudatch logs means you can do the monitoring automatically with the help of Cloudatch logs. Okay. Now, let me give you some example scenario to test your understanding. Okay. And when I'm talking about testing your understanding, I will be checking that how can you relate that for this example scenario which service is a best fit. So my first example scenario for all of you is you need a GPU instance to train a large deep learning model with custom setup. Okay, I hope you have listened to the question very carefully. I can again put that question in front of you. You need a GPU instance to train a large deep learning model with the custom setup. Now question itself is pointing to certain keywords. We are looking for a custom setup. We are looking for a GPU based instance. So answer to this scenario would be easy to everybody. Okay. In a similar manner, let me put few more scenarios in front of you. Like second one is you want to quickly train and deploy a model without managing servers. So here we are talking about deploying and training a model and even we don't want to manage the servers. We're looking for flexibility. So we know Sage Maker is a best choice for this kind of use cases. Okay, you want to trigger predictions when a new file lands in S3. So here we are talking about eventdriven use cases. Always try to understand the keywords from the scenario itself which can give you a right choice for a service. So as I told you in my this particular scenario we're talking about eventdriven. So answer would be lambda. Okay. Next we have you're building a data science pipeline that includes data prep-processing training and deployment. Okay, so here we are talking about building a pipeline. So you can make use of Sage Maker pipeline. Okay, that is a feature of Sage Maker only. Next, if I'm talking about you need fine grained control and custom networking whenever we're talking about customization. So here customization is related to control. If you will be having control then you would be able to do the customization. So here answer would be EC2. Okay. So this was a quick introduction where I wanted to give you an overview on EC2, SageMaker and Lambda. And I wanted to make a quick comparison that where EC2 is a best fit, where Lambda is a best fit and where Sage Maker is a best fit. Okay. So EC2 is best for custom machine learning environment. Sage Maker is best for end to end machine learning pipelines and Lambda is a good choice for eventdriven or realtime inference. Okay. And we have compared all these services on different factors. Let's say if I'm talking about manage, EC2 is not managed. On the other side, Lambda and Sage Makers are managed. If I'm talking about longunning jobs, EC2 and Sage Maker are good fit for longunning jobs where Lambda is not a good fit for longunning jobs due to the limitation of Lambda of 15 minutes execution time. Okay. Training support in EC2 the training support would be custom in Sage Maker it is builtin as SageMaker is designed for this for Lambda it is limited. If I talk about inference means API serving. Okay. EC2 supports this. Sage maker again supports this. Lambda is a good choice if you are dealing with short jobs. Scalability again in EC2 it is manual. If you have to make it automatically you have to use autoscaling. Sage maker and lambda provides you auto scalability. Cost efficiency. EC2 is good if you are optimizing it. Sage maker is medium and lambda is excellent for short jobs. Okay. So recommendation is beginners and managed machine learning workflow make use of SageMaker. Advanced custom environment or cost optimization make use of EC2. Eventdriven lightweight machine learning or ETL make use of Lambda. So this is something I wanted to help you out as a part of this particular video lecture. Soon we are going to talk about more on this particular track and we will be seeing some hands-on exercises. We are going to talk about launching an EC2 instance for Jupiter notebook and install the Python packages. We are going to perform this particular exercise in two ways means either you can launch an EC2 instance and then you can follow the required installation steps means you can create a virtual environment you can install the Jupyter notebook you can configure it and if you have to install the other Python packages you can do it very easily don't worry I will be giving you step-by-step instructions to do that apart from it. What else you can do? You can also write a program in a Jupyter notebook and using SDK or programmatic way you can interact with AWS services. So I will be showing you both the ways going further. So let's start with the first part of this particular lecture where I will be showing you how to launch an EC2 instance and how to do the required setup. I have taken all these steps here which I'm going to follow one by one. But first of all, let me take you all to the AWS account. So I am expecting till the time all of you would be having an active AWS account with you. So without any further delay, this is my console home. You also call it as a landing page. And you know if you have to explore or navigate to any AWS service you can type the name of the service in the search bar like I'm going to do. Okay. If you have recently visited that service you can also see that particular service in the recently visited section. But for here I'm typing EC2 in the search bar [snorts] and I will be navigating to EC2 dashboard. Here in the EC2 dashboard, I'm going to click on instances and let's quickly launch an EC2 instance. So click on launch instance. The first thing I'll be providing, I'm going to provide a name. Now name is a tag means tag comes from tagging which is a strategy or a best practice we use in order to provide key value pairs or name value pairs to our AWS resources. And the purpose behind tax is to make the search easier or to manage the resources easily. Now you can give any name to this particular EC2 instance. For the demo purpose, I'm giving a name called demo server. So let me type demo server here. Next thing which comes into picture that is an AMI. Understand AMI as the Amazon machine image which is containing the prerequisite required to launch this EC2 instance. This prerequisite can be in terms of OS, it can be in terms of application server and applications. For this particular demonstration, I'm using Ubuntu as the AMR. Okay. So once I have chosen Ubuntu the next step would be in order to provide more details like instance type I need to provide. Now if you are a part of a free tier or if you have created the account recently ensure two things while you are going to launch an EC2 instance you have to choose the AMI which is free tier eligible and also you have to choose an instance type which is free tier eligible. Keep pair usually we use if we have to connect to this EC2 instance externally. Okay, externally means if we are using any remote client to connect to this EC2 instance. But right now I will be using a builtin interface present in the AWS management console itself. So in the keep here I'll be saying proceed without a keep here. Restrol settings I'm keeping default for the time being. For example, I am allowing SSH traffic from anywhere. Okay. And all other settings are as it is. Click on launch instance. And we will be waiting for the instance to be launched successfully. Once the instance is ready, you will be getting this message successfully initiated the launch of instance and click on this particular instance ID. You will be navigated to AWS EC2 dashboard. From here you can track the status of your EC2 instance. And once it is in a running state, we are going to connect to this particular EC2 instance and follow the steps further. So click on connect button and then you're going to see this particular interface called EC2 instance connect which we will be using for our demonstration. So click on connect button and you will be seeing a terminal in the browser. So this EC2 instance connect is a built-in interface as the part of AWS management console. So once you are connected to your EC2 instance via EC2 instance connect now let's follow the installation steps. So let me clear this window first and then our first task is to install Python PIP and virtual environment. So you know if you want to check Python is present or not simply check the Python version and it is saying Python not found. Okay, it is saying did you mean command python 3 from dev python 3 or command python from deb python is python 3 means these are some Linux instructions if you are not from the administration background or Linux background don't worry about it you can follow these instructions I am executing my first command that is pseudoapp update okay you don't have to memorize these commands you can always get these commands handy in the documentation Means anytime if you're planning to use AWS resources or EC2 instance in order to do your setup, you can get this commands very easily handy. Okay, let me quickly now follow the next one. This command is used in order to install the Python PIP and virtual environment. And [snorts] what I'm expecting once the installation would be completed, I would be able to see the Python version. So let's wait for the progress to be completed up to 100%. You can track the progress from here and wait for this to be completed up to 100%. Okay, how can we check now? If you're going to execute your command again Python version. Okay, it is still saying command Python not found. Let's try with Python 3 version. It is giving me this is a Python version. Okay, next step is what we are going to do. We will be creating a virtual environment and install Jupiter. So let's again follow these steps everybody. We are going to execute these commands one by one. You have to understand the end goal what exactly we are doing here. The purpose is to create a virtual environment and pip we are using in order to install Jupiter and other libraries. Okay. So these are the other packages which you can install using pip. Let me do it everyone. Okay. Once this particular step would be completed what is the next step everybody? We have to configure Jupyter notebook. Configuring Jupyter notebook means you have to generate a config file. You have to set the password and you have to addit the config in order to allow the traffic. Means we want to access this Jupyter notebook from the browser. Okay. So let's follow these steps everyone. Let me go back. I'm waiting for these installations to be completed. Again you can see the packages count from here. like how many you have to install and how many are easily get installed. So let's wait. Okay, it's done. So I'm generating a config file. Later I'm going to set the password. It will be asking to type a password. You have to verify it. Don't worry, it will be taking that in the background. Okay, it is saying rot hashed password to this particular config.json file. Okay, later we have to addit the config. This config we have to add it in order to allow the traffic. Okay, so let's wait. We are going to add couple of lines here. Let me do it. Let me provide this and I'm going to add it. Okay. Now this is a nano editor. So like you have in Windows, Notepad++, Notepad, Wordpad all these are editors. Similarly in Linux you have different editor. One such editor is nano editor. Okay. So I opened a file. If you have to insert something you can directly start typing. If you have to do a copy paste you have to say control C and control shift V. For pasting you have to use control shift V. Now in order to save the changes press Ctrl X say Y and enter. The changes will be written to this particular file. Now next step is we have to start the Jupyter notebook. Let me do it. I'm going to start the Jupyter notebook from here. Now what is my expectation? I have to access this Jupyter notebook in the browser. Now how I'm going to access this Jupyter notebook in the browser. For that I have to take the public IP and once it is copied you have to take that in the browser type http col/ slash this public IP then colon 8888 this particular port number we had set or you can also call it as a default port number for your Jupyter notebook. Now when I'm going to press enter what's the expectation are you expecting to get access to Jupyter notebook let's see if not then we have to troubleshoot what is wrong so for the time being I already have some hint in my mind that if it's not going to work what I have to look into let me help you out so basically like we need to check few things whenever we are dealing with EC2 instances and one such thing is security group so Security group basically act as a firewall. This firewall basically help you out in order to decide what type of traffic will be accepted by an EC2 instance. And how can we set this firewall? So go back to the instance details page. If you will scroll down, you have a security section. Under security section, you have a security group. Quickly open this security group. And from here all of you can see you have the inbound rule. Inbound means traffic coming in. Outbound means traffic coming out. So right now I'm talking about inbound rows. I have to addit an inbound row. And what I need to do I have to allow a traffic on a specific port that is 888. Okay. From where you want to allow the traffic that you need to decide for the demo purpose. Usually like if you are working with your team members and you want to give them the access to this particular IP, you can allow it from a specific IP range or you can allow it from anywhere. But remember this is only for demo purpose. But for this particular demonstration, I will be allowing the traffic from my IP. Means when the request on this port number will be coming from my IP, then only it will be allowed. Let's save the rules. Come back here and refresh the page. Can you see this time I'm going to get the Jupiter login page. Let me provide the password. This is the same password you had set while doing your configuration. And once you will click on login, after providing the password, you will be seeing a Jupyter notebook. You'll be seeing a Jupyter environment. Okay. You can basically open the terminal from here and in this terminal let's say if you have to install some additional packages you can do it. Let me show you. So let me paste it here and press enter what it's going to do. It's going to install all these packages. Okay. So once the installation would be done, you will be able to see all these packages has been installed as a part of your setup. So what was the idea? The idea idea was to show you how can you launch an EC2 instance and set up a Jupyter notebook along with installation of other packages. Now, as I told you, I'm going to show you one more way that is a programmatic way in order to launch an EC2 instance using a script. Okay. And I have already taken a script for all of you which I will be executing as a part of my next step. So, let's move towards the next part where we are going to follow the steps in order to launch an EC2 instance programmatically. 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 Jupyter 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 spacey 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 1. 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 key pair 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. 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. [snorts] 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 allowing 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 three 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, whichever 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 our 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. We are going to talk about introduction to Sage Maker notebooks manage Jupiter with easy scaling. So before I'm going to take you towards the AWS management console, let me take you towards the AWS documentation. So this is the AWS documentation where you can get an idea about Amazon SageMaker notebooks. You can obviously search on internet Amazon SageMaker notebook and the best way to learn about any AWS service is AWS documentation. So oneliner statement you can get from here that is a fully managed notebooks in Jupyter lab for exploring data and building ML models. When you will click on launch Jupyter lab in Sage Maker Studio you will be navigating to your AWS management console. Soon I'm going to take you there. But before that if you want to get an idea little bit more you can understand from here means you can launch a fully managed Jupyter lab from Sage Maker Studio in seconds. You can use the IDE for notebooks code and data. You can use a quick start collaborative notebooks in the IDE to access purpose-built ML tools in SageMaker. So, Sage Maker is very popular ML service and SageMaker notebook is one of such feature. Okay. You can also say like you can leverage other AWS services for your complete ML development from preparing data at pabyte scale using spark on EMR to training and debugging models. More you can read about SageMaker notebooks from this particular definition. When it comes to benefits, the benefits starts with quick start, high performance, fully managed infrastructure. You don't have to worry about underlying infrastructure code faster with AI powered coding companions and scale data preparation. You can obviously expand this plus icon in order to know how you can quick start with the notebook. Okay. Later you can see build ML at scale elastic compute and quick start means you can scale your underlying compute resources up or down and you can also use the shared persistent storage to switch compute all without interrupting your work. So let's boost your ML development productivity for data preparation, notebook jobs, AI powered tools and here you can get an idea about all these things. When it comes to flexibility and customization, it is built for teams customizable also provide you standalone notebook instances. These are some of the customer stories from where you can get an understanding like how this Sage Maker AI and Sage Maker notebook is helping you out in order to leverage different features. So this is a very short introduction where I wanted to help you out with respect to Sage Maker notebook. So if I have to conclude I can say Sage Maker notebook is the manage Jupyter environment. Okay, it's easy to build and run machine learning workload without worrying about infrastructure setup. So with this we are going to move towards AWS management console. Now in the management console if you have to navigate to a particular service you can type the name in the search bar as I've already done and I am landing to Amazon Sagemaker dashboard and you will be seeing this info message Amazon SageMaker AI formerly named Amazon SageMaker. So you can navigate to SageMaker AI from here or you can type that in the search bar again. Now I have clicked on go to Amazon SageMaker AI and you will be navigated to another dashboard where you can see different features or you can explore different features. So under application and IDE you can see notebooks. This is something I was talking about. So you can try the new Jupyter lab in the Sage Maker Studio. If you have to create a notebook instance, you can click on create notebook instance from here. And once you're going to click on create notebook instance, you need to provide certain configurations. You have to choose instance type. You have to choose platform identifier. You have to provide IM role and little bit more things. So I will be soon showing you one hands-on exercise using this Jupyter notebook. Let's move towards the hands-on exercise. So in this particular hands-on exercise, what we are going to do, I have already listed down here. So we will be having a quick scikitlearn demo that runs entirely in the notebook. No SageMaker jobs free aside from the notebook runtime. Simple Sage Maker XG Boost demo that runs a manage training job using Sage Maker's built-in XG boost container. This is going to incur a training job cost while it runs. So now it's up to you if you want to stay in a free tier. If you don't want to perform anything which is going to incur charges in your account, you can get the things very clearly while trying anything new. Okay. Or otherwise you can watch how I am going to try this in my AWS account. So first thing what we are going to do we will be launching a notebook instance. Now I have already launched a notebook instance in my account just to save time but I will be giving you a quick walk through how to launch a notebook instance. Click on create notebook instance and your journey starts here. You have to provide the details. Let's say notebook instance name any name you want to provide. Notebook instance type whatever you want to choose. I have chosen ML.T2.xlarge. Okay. Instance type talks about the specifications and these specification varies based on type of workload you want to run. So as I told you I have chosen this one mlt2.xlarge. This is my instance type. Later comes permissions and encryption. Now when you are trying AWS services and majorly when you have to establish interaction among multiple AWS services permission is very must. So how can you manage permissions when you have to allow interaction among different AWS services? The straightforward answer to this is IM rule. So you can create a new IM rule like this. You can select what permissions you want to provide for the S3 bucket. Do you want to provide the permissions to any S3 bucket or a specific S3 bucket? The instance which I had launched in my account, I had provided the permission to any bucket. Click on create role. I have already created so I'm not going to create it again. Okay. And with all these settings click on create notebook instance. So three things you have to provide the notebook instance name the notebook instance type and then in the permission you have to provide a specific IM role. Okay, I am clicking on cancel button as I already have a Jupyter notebook instance in my account and the status is in service. So remember you have to wait for the status to be in service. Now few things I will be ensuring. I can directly open the Jupyter lab from here but I want to follow few things and what are those? I will be checking this is the ARN. Okay, ARN stands for Amazon resource name. It is a unique identifier which is given to the AWS resource and majorly it is used in the policy. Okay. Now this is a IM role ARN. This im ro ARN we will be using as a part of our codebase. So let me open this. If you want to open this, it will be taking you to the IM console. That's fine. Click on open Jupyter lab and it will be redirecting you to the Jupyter lab notebook. Okay. Now in the meantime let's quickly walk through the steps we're going to perform. Use a Python 3 kernel in the SageMaker Studio or notebook instance. The notebook must run inside Sage Maker or you must supply a valid IM role ARN. So I told you while I was creating a notebook instance I had created a new I'm rule and when running the SageMaker training job you will be charged for the instance used by the job. Okay. So let's go back and we are going to create a notebook. Okay. This is our runtime. You can see you can select the kernel from here. Let me select this one only which was already selected. Okay, once it is selected, if you want, you can rename it. Okay, I'm not doing it for the time being. Quickly go here and run the first cell to import the libraries and pick up the SageMaker role. Okay, so I'm going to execute the setup step. Let me do that. This is my codebase. What we are exactly doing here? You can see we're installing certain libraries and then we are providing the role. So here I have to replace the role ARN the one which we had seen there. You can directly take it from here. Click on ARN and copy. Okay. Once it is done you can run this cell and let's see the output. If everything would be fine, you're going to see the output. It is downloading the requirement and then later what it will be doing, it will be using a default bucket or create a one for you. So once the collected packages and installation is successfully done, it will be following the further execution steps. Let's wait for the execution to be completed. Okay. And you can see the execution is completed successfully. If you want to browse for this S3 bucket in your account, you can do that. So go to S3 dashboard and what you will be doing, you will be navigating to the S3 dashboard to search for this bucket which got created. Let's do that. And you'll be seeing a bucket created. Okay, come back here. What's the next step everybody? The next step is we are going to perform quick scikit learn demo. Okay, we'll be loading a data set. We're going to split, we'll be training it, we'll be evaluating it and saving it. So no sage maker training job required. It is good for quick iteration. So we are going to show a typical train, evaluate and save flow using the Iris data set. Okay, let me take this part. Train and evaluate. I'm just going to copy the code base and I will be taking it here. Let me paste it here. Okay. If you want you can go through this codebase. This is something I'm doing importing the libraries defining the X and Yaxis and then I am basically doing a train test split. Finally, saving the model locally and upload it to the S3, which is an optional step. Let me run this and we're going to see the output and the execution result. You can see this is the execution result. It has saved the local model to the S3. Let's go back and let's see if something is present inside this S3 bucket. You can see this model is present inside this S3 bucket. Come back here. Now the next step is we are going to prepare a CSV train test files. We'll be uploading to S3. We'll be providing a minimal train. Python script that XG boost container will run. We'll be launching a SageMaker XG boost training job. Download the model artifact and do a quick local evaluation. Okay. So, we are going to create a CSV train and upload. Okay. So, here the first step is prepare data and upload to S3. Let's do that. I'm going to take this piece of code again. and we're going to upload it to S3. Let's go back, provide the code base and click on run button. You can see this is the S3 train path and test path. Okay. Later if you want you can refresh it and you can again come back here and check what exactly it has done. You can go back here. Yes, it is here inside XG boost. Okay. Now next step is we'll be again going back to our notebook instance. We'll be creating a training script. train py. So we're going to create a file in the notebooks working directory named train py. It will be executed inside the container. Okay, let me do that. So we're going to write a minimal script for SageMaker XG boost container. Let me take this one and I'm going to use it. So what I'll be doing I will be doing a right click new file let's say I'm giving a name train py and press enter okay let's open this file and paste the code base okay this is a code base which we have pasted here you can again check if you want to follow the same convention the convention is we're going to create a train py file Okay, once it is done, the next step is we're going to launch the SageMaker XG boost training job. So, we will be using the SageMaker SDK XG boost estimator. This will launching a manage training job. Okay. So, let's take the code from here and we are going to use that in our notebook. I'm going to do a copy paste. Let me take it and then we will be pasting it in our notebook. Let's run this cell and wait for the output. It is creating a training job with this name. It will be taking couple of minutes. So, we'll have to wait for the training job to be completed. So, once it will be completed, I'll be joining back and I will be showing you the further steps. So, we can see the status here. a training job completed and it is also uploaded the generated training model. What's the next step? Next step is if I'll be taking you here in the document what we will be doing, we are going to download the train model and run a quick local test. Let's do that. Let me take this piece of code and we are going to perform the required actions. Let me paste it here and let me run the cell. You can see this is a classification report which we have got. Okay. Now the last part is what we will be doing. If you are done till all these steps or if you have watched all these steps clearly don't forget to clean your environment. That is very much required because if you don't want to get any additional cost you have to clean the environment. So you will be cleaning up to avoid cost and clutter. We are going to remove S3 object you created and delete any endpoint if you deployed one. Let me delete S3 object under the prefix. Let's use this and execute it here. Okay, it has deleted the S3 object. What you can do once you will be done, I will suggest you don't forget to delete this notebook instance. Okay, how to do it? Go to SageMaker AI dashboard and in the SageMaker AI dashboard from the left hand side you have to open the notebook. Let's wait for this particular dashboard to appear. Go to notebooks. In the notebooks, you can see a notebook instance. I will be telling you the steps and then you can do it accordingly. Let me refresh this one. You have to ensure you are in a correct region. Let's say I'm performing most of my exercises in Mumbai. So I will be navigating back to Mumbai region. And here I will be able to see the instance notebook instance which I had created. Okay. Select it. Two actions you have to perform. First of all, you have to stop it. Once it is stopped, this delete option will be enabled and then you are going to delete it. Okay. So what exactly we have done in this particular exercise as I told you we had a quick scikitle learn demo that runs entirely in the notebook and we had also showcase simple sage maker xg boost demo that runs a manage training job using sage maker's built-in xg boost container. Okay. So now what you can conclude? You can say data scientists can scale experiment beyond their local machine by leveraging cloud computing options like EC2 and SageMaker. And if I will be asking you what it provides, it provides flexibility, scalability and reproducibility for ML workflows. [clears throat] Even you don't have to manage the underlying infrastructure if you don't want to. If you focus on writing the piece of code, you can do and all these things we have very clearly seen through various hands-on exercises. Thank you very much for watching this video lecture.

Original Description

Struggling to choose the right AWS service for your machine learning project? This comprehensive guide breaks down the three essential AWS compute options for data science: EC2, SageMaker, and Lambda. We explore the critical differences in control, cost, scalability, and management to help you make the best choice for your specific needs. Join us as we go from theory to practice with three in-depth, hands-on demos: - Full Control with EC2: Learn how to manually launch an EC2 instance, set up a complete Python and Jupyter Notebook environment from scratch, and configure networking. - Automation with Boto3: Discover how to programmatically launch and configure an EC2 instance for data science using a Python script in a local Jupyter Notebook. - Managed ML with SageMaker: See how to leverage the power of SageMaker Notebooks to run a scikit-learn model and then scale up with a managed SageMaker XGBoost training job, simplifying your entire ML workflow. Whether you're a data scientist, ML engineer, or cloud enthusiast, this video will provide the clarity you need to build, train, and deploy models efficiently on AWS. Timestamps: 0:00 - Introduction: The Need for Compute in Data Science 0:58 - Comparing EC2, SageMaker, and Lambda 3:24 - Deep Dive: AWS EC2 Explained (Total Control) 4:31 - Deep Dive: AWS Lambda Explained (Event-Driven & Serverless) 5:19 - Deep Dive: AWS SageMaker Explained (Managed ML Platform) 6:08 - Feature Comparison: Compute Control, Cost, and Scalability 10:33 - Maintenance & Management Differences 12:16 - Example Scenarios: Which Service is the Best Fit? 16:58 - Demo 1: Setting up Jupyter on an EC2 Instance 18:51 - Launching the EC2 Instance from the AWS Console 22:05 - Installing Python, PIP, and Virtual Environment via SSH 24:40 - Configuring the Jupyter Notebook Server 27:44 - Troubleshooting: Configuring the Security Group to Allow Access 30:20 - Demo 2: Programmatic EC2 Setup with Python (Boto3) 33:17 - Writing the Boto3 Script to Launch and C
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 The DataHour: Data Science in Retail
The DataHour: Data Science in Retail
Analytics Vidhya
2 The DataHour: Anomaly detection using NLP and Predictive Modeling
The DataHour: Anomaly detection using NLP and Predictive Modeling
Analytics Vidhya
3 The DataHour: Energy Data Science Project from Scratch
The DataHour: Energy Data Science Project from Scratch
Analytics Vidhya
4 The DataHour: Explainable AI Need and Implementation
The DataHour: Explainable AI Need and Implementation
Analytics Vidhya
5 The DataHour: Google Cloud AI/ML
The DataHour: Google Cloud AI/ML
Analytics Vidhya
6 Prediction to Production in Machine Learning #machinelearning #prediction
Prediction to Production in Machine Learning #machinelearning #prediction
Analytics Vidhya
7 Practical Applications of Data science in Ecommerce
Practical Applications of Data science in Ecommerce
Analytics Vidhya
8 How to tackle Overfitting?#machinelearning #overfitting
How to tackle Overfitting?#machinelearning #overfitting
Analytics Vidhya
9 Building Data Pipelines on GCP #googlecloud #datapipelines #data
Building Data Pipelines on GCP #googlecloud #datapipelines #data
Analytics Vidhya
10 Hands-on with A/B Testing #abtesting #datascience
Hands-on with A/B Testing #abtesting #datascience
Analytics Vidhya
11 Efficient Implementations of Transformers #transformers #cnn  #machinelearning
Efficient Implementations of Transformers #transformers #cnn #machinelearning
Analytics Vidhya
12 Modern Deep Learning Architecture #deeplearning  #architecture #deeplearningtutorial
Modern Deep Learning Architecture #deeplearning #architecture #deeplearningtutorial
Analytics Vidhya
13 Key steps for Designing Artificial Neural Network (ANN) for Image classification #machinelearning
Key steps for Designing Artificial Neural Network (ANN) for Image classification #machinelearning
Analytics Vidhya
14 5 things you should know about Azure SQL #azure #sql #datahour #datascience
5 things you should know about Azure SQL #azure #sql #datahour #datascience
Analytics Vidhya
15 AI & ML in the Automotive Industry #machinelearning #ai
AI & ML in the Automotive Industry #machinelearning #ai
Analytics Vidhya
16 Building Machine Learning Models in BigQuery
Building Machine Learning Models in BigQuery
Analytics Vidhya
17 NLP aspects in Telecommunication Industry
NLP aspects in Telecommunication Industry
Analytics Vidhya
18 Practical Time Series Analysis
Practical Time Series Analysis
Analytics Vidhya
19 Fundamentals of Quantum Computing
Fundamentals of Quantum Computing
Analytics Vidhya
20 A DAY IN THE LIFE of a Data Scientist (From waking up to working on algorithms)
A DAY IN THE LIFE of a Data Scientist (From waking up to working on algorithms)
Analytics Vidhya
21 Classification Machine Learning Model from Scratch
Classification Machine Learning Model from Scratch
Analytics Vidhya
22 Knowledge Graph Solutions using Neo4j
Knowledge Graph Solutions using Neo4j
Analytics Vidhya
23 Model Guesstimation (MLOps)
Model Guesstimation (MLOps)
Analytics Vidhya
24 ETL Pipelines in Google Cloud Platform
ETL Pipelines in Google Cloud Platform
Analytics Vidhya
25 Key steps for Designing Convolutional Neural Network(CNN) for Image Classification
Key steps for Designing Convolutional Neural Network(CNN) for Image Classification
Analytics Vidhya
26 Getting Started with AWS EC2 #amazon #aws
Getting Started with AWS EC2 #amazon #aws
Analytics Vidhya
27 How to Use Azure NLP and Graph Databases for Intelligent Knowledge Mining
How to Use Azure NLP and Graph Databases for Intelligent Knowledge Mining
Analytics Vidhya
28 Certified AI & ML BlackBelt Plus Program #shorts
Certified AI & ML BlackBelt Plus Program #shorts
Analytics Vidhya
29 Visualizing Data using Python #machinelearning #visualization #python
Visualizing Data using Python #machinelearning #visualization #python
Analytics Vidhya
30 DCNN for Machine RUL Prediction using Time-series Data #timeseries #machinelearning #datascience
DCNN for Machine RUL Prediction using Time-series Data #timeseries #machinelearning #datascience
Analytics Vidhya
31 M in ML stands for Math & Magic
M in ML stands for Math & Magic
Analytics Vidhya
32 An Unsupervised ML approach using Clustering
An Unsupervised ML approach using Clustering
Analytics Vidhya
33 Customizing Large Language Models GPT3 for Real-life Use Cases #gpt3 #datascience
Customizing Large Language Models GPT3 for Real-life Use Cases #gpt3 #datascience
Analytics Vidhya
34 Model Parameters vs Hyperparameters - Techniques in ML Engineering #machinelearning
Model Parameters vs Hyperparameters - Techniques in ML Engineering #machinelearning
Analytics Vidhya
35 Practical MLOps #mlops #datascience
Practical MLOps #mlops #datascience
Analytics Vidhya
36 Data Engineering with Databricks #dataengineering #databricks
Data Engineering with Databricks #dataengineering #databricks
Analytics Vidhya
37 Multi-Objective Optimisation
Multi-Objective Optimisation
Analytics Vidhya
38 When Airflow Meets Kubernetes
When Airflow Meets Kubernetes
Analytics Vidhya
39 AI in Banking
AI in Banking
Analytics Vidhya
40 Learn Convolutional Neural Network for Image Recognition
Learn Convolutional Neural Network for Image Recognition
Analytics Vidhya
41 Extracting Value from Data
Extracting Value from Data
Analytics Vidhya
42 How to measure Marketing Channel Effectiveness
How to measure Marketing Channel Effectiveness
Analytics Vidhya
43 Transforming Lives | Data Science Immersive Bootcamp
Transforming Lives | Data Science Immersive Bootcamp
Analytics Vidhya
44 Stock Market Analysis - AI driven approach
Stock Market Analysis - AI driven approach
Analytics Vidhya
45 Become a Data Engineering Professional in 2022 | Future Trends + Skills Required
Become a Data Engineering Professional in 2022 | Future Trends + Skills Required
Analytics Vidhya
46 Ensemble Techniques in Machine Learning #machinelearning #ensemble #datascience
Ensemble Techniques in Machine Learning #machinelearning #ensemble #datascience
Analytics Vidhya
47 The Power of Visualization | Tableau Full Course | Analytics Vidhya
The Power of Visualization | Tableau Full Course | Analytics Vidhya
Analytics Vidhya
48 Demand for Data Engineers is on the Rise | Data Engineer | Analytics Vidhya
Demand for Data Engineers is on the Rise | Data Engineer | Analytics Vidhya
Analytics Vidhya
49 Data Visualization in Data Science | DataHour | Analytics Vidhya
Data Visualization in Data Science | DataHour | Analytics Vidhya
Analytics Vidhya
50 Role of Optimization in Machine Learning & Deep Learning | DataHour | Analytics Vidhya
Role of Optimization in Machine Learning & Deep Learning | DataHour | Analytics Vidhya
Analytics Vidhya
51 Solving any Machine Learning Problem | Approach and Steps Involved
Solving any Machine Learning Problem | Approach and Steps Involved
Analytics Vidhya
52 Topic Modeling Explained with Implementation | Using LDA in Python | DataHour by Arpendu Ganguly
Topic Modeling Explained with Implementation | Using LDA in Python | DataHour by Arpendu Ganguly
Analytics Vidhya
53 Data Engineering in E-Commerce | The Best Case Study
Data Engineering in E-Commerce | The Best Case Study
Analytics Vidhya
54 Introduction to Classification using Azure Machine Learning | DataHour | Analytics Vidhya
Introduction to Classification using Azure Machine Learning | DataHour | Analytics Vidhya
Analytics Vidhya
55 Introduction to Federated Learning | DataHour | Analytics Vidhya
Introduction to Federated Learning | DataHour | Analytics Vidhya
Analytics Vidhya
56 Diffusion Models for Generative Arts | DataHour | Analytics Vidhya
Diffusion Models for Generative Arts | DataHour | Analytics Vidhya
Analytics Vidhya
57 Master Google Analytics in 1 Hour | DataHour | Analytics Vidhya
Master Google Analytics in 1 Hour | DataHour | Analytics Vidhya
Analytics Vidhya
58 Learn Hypothesis Testing | DataHour | Analytics Vidhya
Learn Hypothesis Testing | DataHour | Analytics Vidhya
Analytics Vidhya
59 A Practical Approach to Kaggle Competition | DataHour | Analytics Vidhya
A Practical Approach to Kaggle Competition | DataHour | Analytics Vidhya
Analytics Vidhya
60 Making AI work for Business | DataHour | Analytics Vidhya
Making AI work for Business | DataHour | Analytics Vidhya
Analytics Vidhya

This video provides a comprehensive guide to choosing the right AWS service for machine learning projects, including EC2, SageMaker, and Lambda, with demos and step-by-step instructions. It covers the basics of cloud computing, machine learning, and serverless computing, and provides practical examples of implementing machine learning workflows on AWS.

Key Takeaways
  1. Launch an EC2 instance and configure it for machine learning workloads
  2. Use SageMaker for building, training, and deploying machine learning models
  3. Implement serverless computing with Lambda for event-driven workloads
  4. Use Jupyter Notebook for data exploration and machine learning development
  5. Configure IAM roles and ARNs for permissions and encryption
💡 Choosing the right AWS service for machine learning projects depends on the specific requirements of the project, including the need for control, scalability, and cost-effectiveness.

Related Reads

Chapters (15)

Introduction: The Need for Compute in Data Science
0:58 Comparing EC2, SageMaker, and Lambda
3:24 Deep Dive: AWS EC2 Explained (Total Control)
4:31 Deep Dive: AWS Lambda Explained (Event-Driven & Serverless)
5:19 Deep Dive: AWS SageMaker Explained (Managed ML Platform)
6:08 Feature Comparison: Compute Control, Cost, and Scalability
10:33 Maintenance & Management Differences
12:16 Example Scenarios: Which Service is the Best Fit?
16:58 Demo 1: Setting up Jupyter on an EC2 Instance
18:51 Launching the EC2 Instance from the AWS Console
22:05 Installing Python, PIP, and Virtual Environment via SSH
24:40 Configuring the Jupyter Notebook Server
27:44 Troubleshooting: Configuring the Security Group to Allow Access
30:20 Demo 2: Programmatic EC2 Setup with Python (Boto3)
33:17 Writing the Boto3 Script to Launch and C
Up next
Containers on Amazon ECS with Mama J
AWS Developers
Watch →