This project demonstrates the implementation of a serverless CRUD (Create, Read, Update, Delete) REST API using AWS Lambda, API Gateway, and DynamoDB. The infrastructure is provisioned and managed with Terraform, and the Lambda functions are written in Node.js 18.
Before you begin, ensure you have the following tools and accounts set up:
- Node.js (version 18 or later)
- AWS Account
- Terraform (version 0.12 or later)
- AWS CLI
The project is organized into the following directories:
-
modules/
: Contains Terraform modules for infrastructure provisioning.dynamodb/
: Terraform module for DynamoDB.api_gateway/
: Terraform module for API Gateway.lambda/
: Terraform module for Lambda functions.
-
infra/
: Contains the main Terraform configuration files.main.tf
: The main Terraform configuration file.variables.tf
: Variable definitions.outputs.tf
: Output definitions.
-
src/
: Contains the source code for Lambda functions.functions/
: Organized by CRUD operations (create, read, update, delete).
-
tests/
: Contains unit tests for Lambda functions.
-
Clone the repository:
git clone <repository-url> cd my-serverless-api
-
Install Node.js dependencies:
cd src/functions/create npm install cd ../read npm install # Repeat for update and delete directories
-
Install Terraform dependencies:
cd modules/dynamodb terraform init cd ../api_gateway terraform init cd ../lambda_functions terraform init
-
Update the
variables.tf
files in themodules/api_gateway
,modules/lambda
, andmodules/dynamodb
directories with your specific configuration. -
Deploy the infrastructure using Terraform:
cd infra terraform apply
-
Update the Lambda function code in the
src/functions/
directory as needed. -
Redeploy the Lambda functions:
cd infra/lambda_functions terraform apply
Run unit tests for Lambda functions:
cd tests
npm install
npm test