Skip to content

nacholiya/terraform-user-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Terraform Serverless User API on AWS

An end-to-end serverless REST API built on AWS using Terraform (Infrastructure as Code). This project provisions and deploys a backend system using API Gateway, AWS Lambda, and DynamoDB.


๐Ÿ“Œ Project Overview

This API accepts user data (name and age) via an HTTP POST request and stores it in a DynamoDB table.

Key highlights:

  • 100% Infrastructure as Code (Terraform)
  • Serverless and scalable
  • No hardcoded credentials
  • Industry-style AWS architecture

๐Ÿ—๏ธ Architecture Diagram

flowchart LR
    A[Client<br/>Postman] -->|POST /user| B[API Gateway<br/>REST API]
    B -->|Proxy Integration| C[AWS Lambda<br/>Python]
    C -->|Put Item| D[DynamoDB<br/>UserData Table]

    subgraph AWS Cloud
        B
        C
        D
    end
Loading

๐Ÿ”„ Workflow (Request Lifecycle)

sequenceDiagram
    participant Client as Postman
    participant APIGW as API Gateway
    participant Lambda as AWS Lambda
    participant DB as DynamoDB

    Client->>APIGW: POST /user (name, age)
    APIGW->>Lambda: Invoke Lambda (proxy)
    Lambda->>Lambda: Validate & parse JSON
    Lambda->>Lambda: Generate UUID
    Lambda->>DB: Put Item (user_id, name, age)
    DB-->>Lambda: Success
    Lambda-->>APIGW: 200 OK
    APIGW-->>Client: Response (Saved successfully)
Loading

๐Ÿ› ๏ธ Tech Stack

  • Terraform
  • AWS Lambda (Python 3.12)
  • Amazon API Gateway (REST)
  • Amazon DynamoDB
  • AWS IAM
  • Git & GitHub
  • Postman

๐Ÿ“ Project Structure (Explained)

terraform-user-api/
โ”‚
โ”œโ”€โ”€ provider.tf           # AWS provider & region configuration
โ”œโ”€โ”€ iam.tf                # IAM role & policies for Lambda
โ”œโ”€โ”€ dynamodb.tf           # DynamoDB table definition (UserData)
โ”œโ”€โ”€ lambda.tf             # Lambda function & permissions
โ”œโ”€โ”€ apigateway.tf         # REST API, resource, method & deployment
โ”‚
โ”œโ”€โ”€ lambda_function.py    # Python logic to save user data
โ”‚
โ”œโ”€โ”€ .gitignore            # Terraform & Python ignores
โ”œโ”€โ”€ .terraform.lock.hcl   # Terraform provider lock file
โ””โ”€โ”€ README.md             # Complete project documentation

โš™๏ธ Prerequisites

Check installations:

1๏ธโƒฃ Terraform

terraform version

2๏ธโƒฃ AWS

aws --version

3๏ธโƒฃ GIT

git --version

๐Ÿ” AWS Configuration

aws configure

Provide:

  • AWS Access Key
  • AWS Secret Key
  • Region: us-east-1

๐Ÿš€ Deployment (Terraform)

1๏ธโƒฃ Initialize Terraform

terraform init

2๏ธโƒฃ Validate Configuration

terraform validate

3๏ธโƒฃ Preview Changes

terraform plan

4๏ธโƒฃ Apply Infrastructure

terraform apply
Type: yes

๐ŸŒ API Endpoint

POST /user

Invoke URL:

https://<api-id>.execute-api.<region>.amazonaws.com/dev/user

๐Ÿงช Testing with Postman

Method: POST
curl -X POST https://<api-id>.execute-api.<region>.amazonaws.com/dev/user \
-H "Content-Type: application/json" \
-d '{"name":"Nikhil","age":25}'

โœ… Expected Response

{
  "message": "Data saved successfully",
  "data": {
    "id": "uuid",
    "name": "Nikhil",
    "age": 25
  }
}

๐Ÿ—„๏ธ DynamoDB Verification

AWS Console โ†’ DynamoDB โ†’ UserData โ†’ Explore items


๐Ÿงน Cleanup (Destroy Infrastructure)

terraform destroy
Type: yes

๐Ÿ”’ Security Best Practices

  • No secrets committed to GitHub
  • Terraform state excluded via .gitignore
  • IAM role scoped for Lambda

๐Ÿ“š Learning Outcomes

  • Terraform Infrastructure as Code
  • AWS Serverless architecture
  • REST API design
  • IAM permissions
  • End-to-end DevOps workflow

๐Ÿ‘ค Author

Nikhil Acholiya
DevOps / Cloud Engineer


โญ Notes

This project is resume-ready and interview-ready.

About

Serverless REST API on AWS using Terraform (Lambda, API Gateway, DynamoDB)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

โšก