How to Build a Website from Scratch Under the AWS Free Tier (Part II: Back)
by Anas El MhamdiThis article continues a series on budget-friendly website deployment using AWS services. It demonstrates how to construct a serverless backend using AWS Lambda and the Serverless framework.
Introduction
The first part covered hosting static websites via S3 and distributing them securely through CloudFront. This installment addresses adding backend functionality without the typical deployment headaches.
Modern AWS services allow developers to run a fully lightweight and functional backend with a few functions in no time using Lambda functions and the Serverless framework.
Prerequisites
- Active AWS account
- Existing live website
- Node.js installation
- Serverless framework:
npm install -g serverless
Initial AWS Setup
- Access AWS Console’s IAM (Identity Access Manager)
- Create a new user named “serverless-admin” with Programmatic Access enabled
- Attach the AdministratorAccess policy
- Store the generated Access Key ID and Secret Key securely
- Configure credentials:
serverless config credentials --provider aws --key YOUR_KEY --secret YOUR_SECRET
Service Architecture
The Lambda-based API performs three functions:
- Receives a signature from website visitors
- Validates signature authenticity
- Returns verification results to the client
Lambda Function Design
Lambda functions receive event and context parameters. For HTTP requests, the relevant event structure includes:
body: Request payloadhttpMethod: HTTP verb (POST, GET, etc.)queryStringParameters: URL parametersisBase64Encoded: Encoding flag
API Gateway Lambda responses must contain statusCode and body JSON keys; omitting these triggers 500 errors.
Serverless Configuration
Deployment relies on a serverless.yml configuration file at the project root, containing all necessary Lambda deployment specifications.
File Structure
lambda_demo
├── serverless.yml
├── decode_api.py
└── encode_decode.py
Deployment Process
Execute serverless deploy to trigger automated Lambda creation and API Gateway endpoint generation.
Upon completion, the terminal displays the new endpoint URL:
https://s8zszn4fu2.execute-api.eu-west-3.amazonaws.com/dev/check
Testing with Postman
- Copy the generated endpoint URL
- Open Postman and paste the endpoint
- Select POST method
- Set Body tab to Raw format
- Send request
Lambda Logging
Access logs through the Lambda dashboard’s Monitoring tab via CloudWatch Logs. Every Lambda invocation appears logged, facilitating rapid debugging.
Cost Advantages
AWS provides 1 million free Lambda requests monthly, making this approach probably super cheaper than what you considered. This pricing structure suits development and testing without significant expenses.
Achievements
Across both articles, you’ve learned:
- S3-based website hosting
- CloudFront-based secure distribution
- Serverless Lambda backend creation
This foundation enables testing stuff out with minimal financial investment.