Building a Machine Learning API: Integrating AWS Lambda with API Gateway
Key Takeaways
This video demonstrates how to expose a machine learning model deployed on AWS Lambda as a REST API using Amazon API Gateway, covering the integration of Lambda with API Gateway and testing the API.
Full Transcript
Welcome back everybody. So what is our next goal? We want to expose deployed ML model features and get a prediction response. Our model is running in AWS Lambda container. So for a quick recap, I have taken the example request which we had passed while doing a test using Lambda function. So this was our request body and this was the example response which we are expecting. So in short we are going to expose our ML model via APIs. I have also mentioned the steps we are going to perform and then I will be taking you all towards performing these steps one by one. So we will be checking whether our lambda is working fine or not. Then we are going to open the API gateway console which is basically one of the very good service in AWS in order to expose the APIs. If you are not aware about API gateway you can get an understanding API gateway act as a front door for all the APIs request coming from the users and then to redirect it to the backend services. In short, it is acting as a middleware everybody or facade layer. You're going to create a new rest API. You will be creating a post method and integrate with lambda. Then you're going to deploy the API. You're going to test from the API gateway console and then you will be testing using curl or a Python script. Okay. So I will be using a Python notebook in order to do a round of testing. So let's go step by step. Our first step is to ensure that our lambda working fine. So I will be navigating to management console and the first landing place would be lambda. Okay, you all would be already aware that how to get into the lambda console. If not search for lambda in the search bar and you will be navigating to lambda dashboard. Okay, you can always click on this last modified in order to check what was the latest function you had created. In my case, I have this iris ML container. Let me open this and I know that I have basically deployed this particular function using container images. I will be going to test and let me click on test button. We are going to ensure that we are getting the expected response which we had taken as a sample response to and yes we have the exactly the same response we were expecting and mentioned as a sample response. Next thing is go to API gateway everybody. So in the search bar type API and it will start giving you suggestions. So I have got a suggestion for API gateway. I will be opening API gateway. So currently I'm in Mumbai region. You can make a choice of a region as per your requirement. Okay, let me show you something. If you are new to API gateway, you can click on this and read about it little bit. Amazon API gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor and secure APIs. Either you can click on create an API from here. Okay? Or you can go to this particular API section. From here also you can click on create an API. Let's see the region in which no API is existing. Means I want to show you a layout difference. Currently in Mumbai region I am already having so many APIs created. Let me take any other region in which I don't have any single API created. And let's see if there is any layout difference. Okay. So here I don't have any API created. If I will be going to create an API, I'm going to get a similar kind of layout. Okay. So there is no layout difference even if you are having an API existing in your region or not. I'm going back everybody because I'm going to use Mumbai as my primary region for all my exercises. And even you have to ensure like if you are basically using Mumbai for creating lambda and other resources you had used in the past demo then API you have to create in the Mumbai region only. Okay. So let me click on create API. We have different types of APIs. I'm going to choose REST API because REST API provides more flexibility [laughter] and you can also gain complete control over the request and response along with the API management capabilities. Okay, it works with Lambda HTTP AWS services. I want to integrate this API with Lambda function. That is my need. So, click on build and you have to choose new API. If you're already having an existing API, you can select the second radio button and so okay. But as I am going to create a fresh new API. So let me provide the API name. Okay. So let's say I am giving the API name as Iris ML API. If you want you can give any name of your choice. In descriptions you can mention APIs for Iris ML model. Something like this. Okay, the API endpoint type I will be keeping regional. We have different type of API endpoint. Okay, for the time being I will be talking about regional APIs are deployed in the current AWS region. Just remember that much. Okay, if you have chosen Mumbai, it will be deployed in Mumbai region. Let's click on create API. So our API is created. Now we are going to click on create resource. What is resource? Everybody understand resource as the entry point. Whenever you are going to access the APIs, resources will be entry point or you can also call it as the logical grouping. It is useful logical grouping everybody. So let's say I'm creating a resource. I'm giving a resource name as predict and this would be my resource path. Okay, secret resource you can see a resource got created. You will be seeing a resource with slash predict under the slash. Now what is the next thing everybody? Once the resource got created, we have to create a method. Okay. So we will click on create method. We have different types of method. I am going to create a post method. And then the integration type would be lambda. I want to integrate the API with a lambda function. If you have any other requirement, let's say you want to integrate with existing HTTP endpoint, you want to generate a response based on API gateway mappings and transformations. You can choose other radio button. But in our case, we know that our ML model is deployed on Lambda. So we are going to integrate this API with lambda function. Okay. So method you have chosen post and now we are talking about lambda integration. So in the search type Iris ML container. You have selected this. You can adjust other settings if you want. But for the time being we are not changing any logic. We are not providing or maintaining any request header. I'm keeping it very simple. I just want to show you how can you expose it via APIs. Click on create method. So you have created a post method too.
Original Description
Now that your machine learning model is deployed on AWS Lambda, how do you make it accessible to the world? In this tutorial, we walk through the process of exposing your model as a REST API using Amazon API Gateway.
Think of API Gateway as the "front door" for your applications. It acts as a middleware layer that receives requests from users or apps and routes them to your backend Lambda function.
What you will learn in this video:
- API Gateway Essentials: Understanding how API Gateway acts as a facade layer for backend services.
- Creating a REST API: A step-by-step guide to setting up a new API in the AWS Management Console.
- Resources & Methods: How to create a /predict resource and configure a POST method to handle incoming data.
- Lambda Integration: Seamlessly connecting your API Gateway to a container-based Lambda function.
- Regional Deployment: Why choosing the right AWS region (like Mumbai) is critical for low latency and service compatibility.
By the end of this video, you will have a functional API structure ready to receive JSON payloads and return real-time model predictions.
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: ML Pipelines
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
The Only Git Commands You Actually Need — 47 Patterns for Daily Work
Dev.to · The AI producer
Common Next.js Errors (and How I Solved Them)
Dev.to · gary killen
Applying Scalability in Backend (CodeBuddy)
Medium · LLM
Why Every Backend Developer Should Learn Nginx Before Going to Production
Medium · DevOps
🎓
Tutor Explanation
DeepCamp AI