Deploy & Test Machine Learning APIs on AWS: API Gateway, Lambda, and Jupyter

Analytics Vidhya · Beginner ·🔧 Backend Engineering ·4mo ago

Key Takeaways

Deploying and testing machine learning APIs on AWS using API Gateway, Lambda, and Jupyter Notebook, covering API deployment, stages, and testing methods.

Full Transcript

Once you have created the post method with lambda integration, it's a time to deploy the API. We always need an endpoint if we have to call any API. So, we are going to click on deploy API button. It will be asking you, do you want to create a new stage or if you are already having an existing stage, you can make use of it. What is stage? You can relate stage very simply with the environments in the industry. So, basically what happens? Like in industry, we have a concept of environments. We have development environment, staging environment, production environment, pilot prod. The concept of the environment is these are created with the different set of infrastructure for different type of users. For example, if a developer is developing something in the local machine. Now, developer has to provide some common endpoint to others in order to test their work. They can expose their work in the development environment. In a similar manner, production or live environment is for the end users or live users, you can say. In this case, I am creating a new stage, giving a name prod, and saying deploy. So, once it is deployed, I have got the invoke URL. Now, this invoke URL I will be using in order to test my API. As I told you, I will be testing it by three ways. The first way is using this console. The second way is using curl in the cloud shell, and the third one is I will be calling this API from my Jupiter notebook. Okay? So, first thing, let's do a round of testing from the console. How? Go to resources. In resources, you have to select a method. If you will scroll down, you can see you have different sections. Use this arrow, and you will be navigating to test section. Okay? So, here I have to pass the request body, the same which I had taken here. Let me take it. I'm going to paste this request body here. And now, let's click on test button. And let's see what is the result you're going to get. You are getting HTTP status 200, and this is your response body. Predictions zero, class setosa. Okay? The same thing we had seen while we were doing a round of testing using lambda. You can compare it. Come back here, and you can see. Now, the next round of testing we are going to do, that is using cloud shell. So, open cloud shell in new tab. And I'm going to use a curl command in order to do a round of testing. You have to ensure one thing while you are going to use the curl command, everybody. You have to provide the exact URL. Exact URL means this is a sample API invoke URL. You have to replace it with your invoke URL. So, now, from where you are going to get the URL? Let me guide you. Come back to the API Gateway. Either you can go to stages, that is one place. From stages, you can get the invoke URL. Let's take it. And you're going to replace this invoke URL up to prod. Okay? Don't forget to append the resource name, which is the entry point. Take this particular command, and paste it in the cloud shell. And now, let's see the response. Uh let me just quickly correct it. Let's see the error. What is the error it is giving to you? Because we always need to troubleshoot the error if something is wrong. Okay? So, what is wrong here? I can guide you. Let me just paste it again. Let me correct it. Actually, this is not correct. It should be like this. You also need to specify the method type. So, it is curl minus X post, and then you are going to provide all these things. Okay? Just a minute, everybody. Yes. It is already here. You can directly take it from here, test from the cloud shell or local machine. And don't forget to replace the invoke URL. Just take the invoke URL and replace it. As I told you, you have to ensure you have a resource name with you. Let's take this particular command, and execute it in your cloud shell. Okay? So, we had an issue with the syntax. Okay? We were pasting the wrong line of code. That's why we're getting the error. Now, you can see I'm getting the status code as 200, and then I'm got getting a response body. The same thing you had seen in the API console. What is last step, everyone? We want to test it using Python client. So, I am using a notebook, Jupiter notebook, in order to make a round of testing. Okay? So, first of all, don't forget to replace your URL. This is my URL. Let me take it. And then, next step all of you are aware about. You have to open the Jupiter notebook. So, I'm expecting that you all have a setup of client on your local machine. Okay? If you don't have, in my past video lectures, I have already explained you how can you set a Jupiter notebook in your local machine. I'm opening a command prompt, and I have to simply type a command Jupiter notebook. Like this. It's going to open a Jupiter notebook in my browser through my local machine, and then I'm going to invoke this API from Jupiter notebook. Okay? One thing which all of you have to ensure that you have configured the AWS credentials if you want to interact with AWS services. Okay? So, remember, your credentials should be having enough permissions to interact with AWS services. Click on file, new, and notebook. I'm already having the credentials configured on my local machine, so that's why I'm not going to do it again and again. Let me take the piece of code. This is a piece of code which I'm going to use. It's a very simple piece of code. I'm importing the request and JSON. This is a URL. This is a payload. This is a header. Content type application/json, and this is the response. I'm going to run this, and let's see if I'm going to get the response back. Yes, I'm getting the response back. Okay? If you are exploring other tools for API testing, you can also make use of Postman. So, this is something I wanted to show. How can you expose your model via APIs, and we have explored API Gateway as a part of this journey. So, we'll be helping you out with the further discussion on this particular video lecture. So, if I have to tell you a conclusion like what we have achieved exactly, so, we run the trained model on lambda container. We expose the HTTP endpoint via API Gateway. We allow the API Gateway to invoke the lambda function, and then we send the features for prediction using curl or Jupiter notebook. So, in short, we have deployed an end-to-end ML inference API, completely serverless and scalable.

Original Description

Turn your machine learning model into a production-ready service! In this final part of our deployment series, we walk through the process of launching a REST API using Amazon API Gateway and testing it like a professional. What you will learn in this video: - API Deployment & Stages: Understanding environments (Dev vs. Prod) and how to deploy your API to get a live Invoke URL. - Three Ways to Test Your ML API: 1. AWS Console: Direct internal testing to verify the Lambda-API integration. 2. Curl via Cloud Shell: How to structure a command-line request (and fix common syntax errors) to call your endpoint. 3. Python Client (Jupyter Notebook): Using the requests library to send JSON payloads programmatically from your local machine. - Troubleshooting: Common pitfalls when handling API endpoints and resource paths. - Final Conclusion: A summary of how we built an end-to-end, serverless, and scalable ML inference pipeline. By the end of this tutorial, you will know exactly how to expose a trained model as a robust HTTP endpoint that any application can consume.
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 teaches how to deploy and test machine learning APIs on AWS using API Gateway, Lambda, and Jupyter Notebook, covering key concepts such as API deployment, stages, and testing methods. By the end of this video, viewers will be able to design and deploy their own machine learning APIs on AWS.

Key Takeaways
  1. Create a new stage in API Gateway
  2. Deploy the API
  3. Test the API using the console
  4. Test the API using Curl in Cloud Shell
  5. Test the API using Jupyter Notebook
  6. Troubleshoot errors
  7. Use Postman for API testing
💡 To deploy a machine learning API on AWS, you need to create a new stage in API Gateway, deploy the API, and test it using various methods such as the console, Curl, and Jupyter Notebook.

Related Reads

📰
Composer Isn’t Just a Dependency Manager — It’s the Backbone of Modern PHP Development
Learn how Composer is the backbone of modern PHP development and why it's more than just a dependency manager
Medium · Programming
📰
How a frustrating school project led me to build my first CLI tool.
Learn how a frustrating school project inspired the creation of a first CLI tool and discover the process of building a command-line interface using JavaScript
Medium · JavaScript
📰
Stop Storing Money in float64
Learn why storing money in float64 is problematic and how to handle monetary values correctly in Go
Dev.to · Simon Klinkert
📰
Kill the Queue Server, use the EventEmitter in Node.js
Learn to build a zero-dependency job queue in Node.js using an array and the event loop, eliminating the need for external queue servers like Redis or RabbitMQ
Medium · JavaScript
Up next
Indian Express Editorial Analysis by Chandan Sharma - 1 JULY 2026 | UPSC Current Affairs 2026
StudyIQ IAS
Watch →