Skip to content

Latest commit

Β 

History

History
198 lines (150 loc) Β· 5.09 KB

README.md

File metadata and controls

198 lines (150 loc) Β· 5.09 KB

⚑ AWS Lambda REST API Integration

A practical demonstration of how to integrate AWS Lambda with Amazon API Gateway to build a fully serverless REST API β€” scalable, cost-efficient, and easy to maintain.


🌐 Overview

This project shows how to:

  • Create and deploy AWS Lambda functions.
  • Integrate Lambda with API Gateway.
  • Configure RESTful endpoints (GET, POST, PUT, DELETE).
  • Test and validate API responses.
  • Manage deployments through Git and GitHub.
  • βœ… Automate CI/CD with GitHub Actions for linting, testing, and Lambda deployment.
  • βœ… Define infrastructure with Terraform (IaC) for reproducible and consistent environments.

πŸ—‚οΈ Project Structure

lambda-rest-api-integration/
β”œβ”€β”€ .github/
β”‚ └── workflows/
β”‚ β”œβ”€β”€ ci.yml
β”‚ └── deploy.yml
β”œβ”€β”€ terraform/
β”‚ β”œβ”€β”€ main.tf
β”‚ β”œβ”€β”€ variables.tf
β”‚ └── outputs.tf
β”œβ”€β”€ src/
β”‚ └── (Lambda source files)
β”œβ”€β”€ tests/
β”‚ └── handler.test.js
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ README.md
└── ...


βš™οΈ Features

βœ… Serverless Architecture – No need to manage servers
βœ… API Gateway Integration – Seamless connection between client and Lambda
βœ… Scalable & Cost-Efficient – Pay only for execution time
βœ… Secure Endpoints – IAM roles and policies
βœ… Simple Deployment – Works with AWS Console or CLI
βœ… CI/CD Ready – Automated testing and deployment with GitHub Actions
βœ… Infrastructure as Code (IaC) – Terraform-based Lambda provisioning
βœ… Docker Support – Optional local testing or containerized Lambda builds


πŸš€ Getting Started

1️⃣ Prerequisites

Make sure you have:

  • An AWS account
  • AWS CLI configured
  • Terraform (for infrastructure provisioning)
  • Node.js or Python (depending on your Lambda runtime)
  • Postman or curl for API testing

2️⃣ Setup & Deployment

Clone the Repository

git clone https://github.com/iftikhar69/lambda-rest-api-integration.git
cd lambda-rest-api-integration

Deploy Using Terraform

cd terraform
terraform init
terraform plan
terraform apply -auto-approve

Deploy the Lambda Function (Manual Option)

You can deploy via AWS Console or using AWS CLI:

aws lambda create-function \
  --function-name MyLambdaAPI \
  --runtime nodejs18.x \
  --role arn:aws:iam::<your-account-id>:role/<your-lambda-role> \
  --handler index.handler \
  --zip-file fileb://function.zip

Integrate with API Gateway

Open API Gateway in AWS Console.

Create a new REST API.

Add a resource (e.g., /users) and methods (GET, POST, etc.).

Link each method to your Lambda function.

Deploy the API to a stage (e.g., prod).

πŸ” Testing the API Use curl or Postman to test endpoints like:

curl -X GET https://<api-id>.execute-api.<region>.amazonaws.com/prod/users

Run unit tests locally:

npm test

πŸ§ͺ CI/CD Pipeline

This project includes GitHub Actions workflows that:

Automatically install dependencies and run tests.

Deploy the Lambda function on merge to main.

File: .github/workflows/ci.yml

name: Lambda CI
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 18
      - run: npm ci
      - run: npm test

🐳 Docker Support You can run and test locally using Docker:

docker build -t lambda-api .
docker run -p 3000:3000 lambda-api

πŸ“Έ Screenshots πŸ”Ή Lambda REST API Setup Lambda Setup

πŸ”Ή Sample Output / Response

Sample Output


🧩 Tech Stack

Component Description
AWS Lambda Core serverless compute service
API Gateway Manages REST endpoints
IAM Secure permission management
Terraform Infrastructure as Code provisioning
Docker Optional containerized testing
GitHub Actions CI/CD automation
Node.js / Python Runtime for Lambda
GitHub Version control and collaboration

🧠 Learn More


πŸ‘¨β€πŸ’» Author

iftikhar69
πŸ’‘ Passionate about cloud computing, serverless systems, and automation.


πŸͺͺ License

This project is licensed under the MIT License.
See the LICENSE file for more details.