This repository contains the completely serverless backend for PantryPal, built entirely on AWS using Terraform and Node.js.
Before cloning and running the infrastructure, ensure you have the following installed on your local machine:
- Node.js (v20+)
- Terraform (v1.5+)
- AWS CLI (configured with your AWS credentials)
- An AWS Account with sufficient permissions to create IAM roles, API Gateways, RDS databases, Lambdas, and S3 buckets.
-
Clone the repository:
git clone <repo_url> cd pp-backend
-
Install dependencies:
npm install
-
Configure Environment variables: Copy the example environment file and fill in your custom values:
cp .env.example .env
Note: The
setupscript will automatically populate many of these variables (likeDATABASE_URLandAPI_URL) after Terraform provisions the resources.
This project uses a "single-click" setup script that initializes Terraform, provisions all the required AWS infrastructure, and runs Prisma database migrations.
-
Provision AWS Resources:
npm run setup
This process will take a few minutes as it provisions an RDS PostgreSQL database, API Gateway, S3 buckets, Cognito User Pools, and the Lambda function.
-
Deploy Code Updates: If you ever modify the code in
src/, you must bundle and deploy it to the Lambda function by running:npm run deploy
Windows Users: If you get a PowerShell policy error, run
cmd /c npm run deploy.
For a detailed breakdown of the deployment process, please read the deployment.md guide.
Once your infrastructure is successfully deployed, the setup and deploy scripts will output your live API_URL (e.g., https://<api-id>.execute-api.<region>.amazonaws.com/).
You can verify that the API and database are running correctly by checking the health route.
Test Case (cURL):
curl <YOUR_API_URL>/healthTo avoid incurring unwanted AWS charges, you can easily destroy the entire infrastructure (including the database, lambdas, and API gateways) with a single command.
Warning
This is a destructive action! It will permanently delete the RDS database, all user data, and the S3 buckets.
To destroy all resources:
npm run destroyYou will be prompted by Terraform to type yes to confirm the destruction of the resources.