AWS Builder Center

Title: Building a Serverless REST API with Amazon API Gateway and AWS Lambda

Learn to create and deploy a serverless REST API using API Gateway and Lambda through a beginner-friendly AWS hands-on project.

IT Student | Full-Stack Developer | AI/ML & Cloud Enthusiast
Modern applications need APIs to exchange information between frontend interfaces, mobile applications, and backend services.
AWS makes it possible to build APIs without managing traditional servers. Amazon API Gateway handles incoming HTTP requests, while AWS Lambda executes backend logic on demand.

Five important concepts

  1. Amazon API Gateway: Creates and manages HTTP and REST APIs.
  1. AWS Lambda: Runs backend code without server management.
  1. HTTP Methods: Handle operations such as GET, POST, PUT, and DELETE.
  1. IAM Permissions: Control communication between AWS services.
  1. CloudWatch: Monitors API requests, execution logs, and errors.

Hands-on AWS Example: Create a Student Information API

Objective: Build an API that returns student information using API Gateway and Lambda.
Step 1: Create a Lambda function
  • Open AWS Lambda.
  • Choose Create function.
  • Select Python as the runtime.
  • Name it  StudentInfoFunction .
Step 2: Add Python code
import json

def lambda_handler(event, context):
student = {
"id": 101,
"name": "Abhi",
"course": "Information Technology",
"status": "Active"
}

return {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": json.dumps(student)
}
Step 3: Create an API
  • Open Amazon API Gateway.
  • Choose Create API.
  • Select an HTTP API.
  • Add your Lambda function as the integration.
  • Create a GET route with the path  /student .
  • Deploy the API to a stage.
Step 4: Test your API
Copy the API endpoint and open:
 https://your-api-id.execute-api.region.amazonaws.com/student 
Expected JSON response:
{
"id": 101,
"name": "Abhi",
"course": "Information Technology",
"status": "Active"
}
Step 5: Monitor execution
  • Open your Lambda function's Monitor section.
  • View CloudWatch logs.
  • Check API Gateway metrics to understand request activity and errors.

What You Learn

By completing this project, you gain practical experience with serverless computing, API development, HTTP request handling, service integration, and cloud monitoring.
Important: Configure appropriate permissions, avoid exposing sensitive information, and review API Gateway and Lambda pricing. Delete test resources after completing the exercise.
Serverless APIs are a powerful way to build scalable backend services while reducing infrastructure management.
What would you build next using this architecture: a student management API, an e-commerce backend, or an authentication service?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article