Deploy & Test Machine Learning APIs on AWS: API Gateway, Lambda, and Jupyter
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
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: Systems Design Basics
View skill →Related Reads
📰
📰
📰
📰
Composer Isn’t Just a Dependency Manager — It’s the Backbone of Modern PHP Development
Medium · Programming
How a frustrating school project led me to build my first CLI tool.
Medium · JavaScript
Stop Storing Money in float64
Dev.to · Simon Klinkert
Kill the Queue Server, use the EventEmitter in Node.js
Medium · JavaScript
🎓
Tutor Explanation
DeepCamp AI