Serverless Infra

Overview
This project provisions a serverless backend on AWS using Terraform. It creates an API layer, compute functions, and a database, all defined as code.
The goal is to achieve fully automated infrastructure setup, where backend services can be deployed consistently without manual configuration.
Stack
Terraform
AWS Lambda
Amazon API Gateway
Amazon DynamoDB
IAM (roles and permissions)
Architecture
API Gateway → Lambda → DynamoDBTerraform Configuration
Provider
provider "aws" {
region = "ap-south-1"
}IAM Role for Lambda
resource "aws_iam_role" "lambda_role" {
name = "lambda-role"
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [{
Action = "sts:AssumeRole",
Effect = "Allow",
Principal = {
Service = "lambda.amazonaws.com"
}
}]
})
}Lambda Function
resource "aws_lambda_function" "app" {
function_name = "serverless-app"
role = aws_iam_role.lambda_role.arn
handler = "index.handler"
runtime = "nodejs18.x"
filename = "function.zip"
}API Gateway
resource "aws_api_gateway_rest_api" "api" {
name = "serverless-api"
}DynamoDB Table
resource "aws_dynamodb_table" "table" {
name = "app-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "id"
attribute {
name = "id"
type = "S"
}
}Commands
terraform init
terraform plan
terraform applyResult
Serverless backend created using code
API endpoint connected to Lambda
Data stored in DynamoDB
No server management required
Key Points
Infrastructure fully automated
Scalable backend without servers
Pay-per-use architecture
Easy to modify and redeploy
Final Note
This project demonstrates how backend systems can be built and managed entirely through code.
It ensures infrastructure is consistent, scalable, and production-ready without manual setup.

