|
1 | 1 | # Serverless Lambda Project |
2 | 2 |
|
3 | | -This project demonstrates a **serverless web application architecture** using AWS services. The eBook landing page is a sample static website used to showcase how AWS Lambda, CloudFront, DynamoDB, S3, and other serverless services work together to build scalable, cost-effective, and highly available applications. |
| 3 | +This project is a serverless application designed to handle user subscriptions efficiently. It leverages several AWS services including Lambda, CloudFront, S3, DynamoDB, and SES. |
4 | 4 |
|
5 | | -> **Note**: The website itself (eBook Landing) is just a **demo template for testing purposes**. The focus of this project is on the **AWS serverless infrastructure** and cloud architecture patterns, not the website content. |
| 5 | +## Functionality |
| 6 | +- **User Subscription:** Users can subscribe to the website. Upon subscription, an email notification is sent to both the user and the site administrator. |
| 7 | +- **Data Storage:** User subscription data is securely stored in DynamoDB, ensuring easy access and management. |
6 | 8 |
|
7 | | ---- |
| 9 | +## Live Demo |
| 10 | +You can check out the live project here: [Live Link](https://jhgalkj.xyz/) |
8 | 11 |
|
9 | | -## 🌐 Live Demo |
10 | | - |
11 | | -**Check out the live website**: [https://jhgalkj.xyz/](https://jhgalkj.xyz/) |
12 | | - |
13 | | -Experience the serverless architecture in action! The website is deployed using AWS CloudFront and S3, demonstrating global content delivery with low latency. |
14 | | - |
15 | | ---- |
16 | | - |
17 | | -## 🎯 Real-World Problem Solved |
18 | | - |
19 | | -### The Challenge |
20 | | -Traditional web applications require: |
21 | | -- **Server Management**: Maintaining, patching, and scaling EC2 instances or physical servers |
22 | | -- **Fixed Costs**: Paying for servers 24/7, even during low traffic periods |
23 | | -- **Manual Scaling**: Complex auto-scaling configurations and load balancer management |
24 | | -- **Security Overhead**: Managing OS-level security, firewall rules, and infrastructure updates |
25 | | -- **Limited Availability**: Regional outages can bring down the entire application |
26 | | -- **Slow Deployment**: Time-consuming server provisioning and configuration |
27 | | - |
28 | | -### The Serverless Solution |
29 | | -This project addresses these challenges by implementing: |
30 | | - |
31 | | -1. **Zero Server Management** |
32 | | - - No EC2 instances to maintain or patch |
33 | | - - AWS manages all infrastructure and scaling automatically |
34 | | - - Focus on code and business logic, not DevOps |
35 | | - |
36 | | -2. **Pay-Per-Use Model** |
37 | | - - Lambda charges only for actual execution time (billed per millisecond) |
38 | | - - No costs during idle periods |
39 | | - - Significant cost savings for variable workloads (can reduce costs by 70-90%) |
40 | | - |
41 | | -3. **Automatic Scaling** |
42 | | - - Lambda automatically scales from 0 to thousands of concurrent executions |
43 | | - - CloudFront CDN handles traffic spikes globally |
44 | | - - No manual intervention required |
45 | | - |
46 | | -4. **Global High Availability** |
47 | | - - CloudFront distributes content across 400+ edge locations worldwide |
48 | | - - S3 provides 99.999999999% (11 9's) data durability |
49 | | - - Multi-AZ deployment ensures fault tolerance |
50 | | - |
51 | | -5. **Enhanced Security** |
52 | | - - IAM manages fine-grained access control |
53 | | - - No SSH keys or server access to manage |
54 | | - - Built-in DDoS protection with AWS Shield |
55 | | - - Automatic security updates handled by AWS |
56 | | - |
57 | | -6. **Rapid Deployment** |
58 | | - - Deploy code changes in seconds with Lambda |
59 | | - - Infrastructure as Code (IaC) enables repeatable deployments |
60 | | - - CI/CD pipelines automate testing and releases |
61 | | - |
62 | | -### Real-World Use Cases |
63 | | -This architecture pattern is ideal for: |
64 | | -- **E-commerce websites** with unpredictable traffic spikes |
65 | | -- **Marketing landing pages** for campaigns |
66 | | -- **Content delivery platforms** requiring global reach |
67 | | -- **API backends** for mobile/web applications |
68 | | -- **Event-driven applications** (file processing, data transformation) |
69 | | -- **Startups** needing to minimize infrastructure costs |
70 | | - |
71 | | ---- |
72 | | - |
73 | | -## 🏗️ Architecture Overview |
74 | | - |
75 | | -This serverless application leverages the following AWS services: |
76 | | - |
77 | | -### Core AWS Services |
78 | | - |
79 | | -#### 🔹 **Amazon S3 (Simple Storage Service)** |
80 | | -- **What it does**: Cloud storage service that stores your website files (HTML, CSS, JavaScript, images) |
81 | | -- **Role in this project**: Hosts the static website files and serves as the origin for CloudFront |
82 | | -- **Benefits**: 99.999999999% durability, unlimited storage, versioning, and low cost |
83 | | - |
84 | | -#### 🔹 **Amazon CloudFront** |
85 | | -- **What it does**: Content Delivery Network (CDN) that caches and distributes content globally |
86 | | -- **Role in this project**: Delivers website content from edge locations closest to users worldwide |
87 | | -- **Benefits**: Lightning-fast page loads, DDoS protection, HTTPS support, reduced S3 costs |
88 | | - |
89 | | -#### 🔹 **AWS Lambda** |
90 | | -- **What it does**: Runs code without provisioning servers - you only upload your code and Lambda handles everything |
91 | | -- **Role in this project**: Executes backend logic (e.g., form submissions, data processing) on-demand |
92 | | -- **Benefits**: Auto-scaling, pay only when code runs, supports multiple languages (Python, Node.js, etc.) |
93 | | - |
94 | | -#### 🔹 **Amazon DynamoDB** |
95 | | -- **What it does**: Fully managed NoSQL database for storing and retrieving data at any scale |
96 | | -- **Role in this project**: Stores application data like user submissions, analytics, or contact form entries |
97 | | -- **Benefits**: Millisecond latency, automatic scaling, serverless, no database management |
98 | | - |
99 | | -#### 🔹 **Amazon API Gateway** |
100 | | -- **What it does**: Creates, publishes, and manages RESTful APIs that act as a "front door" for applications |
101 | | -- **Role in this project**: Receives HTTP requests from the website and triggers Lambda functions |
102 | | -- **Benefits**: Request throttling, caching, authorization, monitoring |
103 | | - |
104 | | -#### 🔹 **AWS IAM (Identity and Access Management)** |
105 | | -- **What it does**: Manages access permissions and security policies across AWS services |
106 | | -- **Role in this project**: Controls which services can access each other (e.g., Lambda accessing DynamoDB) |
107 | | -- **Benefits**: Fine-grained permissions, security best practices, audit logging |
108 | | - |
109 | | -#### 🔹 **AWS CloudWatch** |
110 | | -- **What it does**: Monitoring and logging service for AWS resources and applications |
111 | | -- **Role in this project**: Tracks Lambda execution, error rates, API calls, and system health |
112 | | -- **Benefits**: Real-time monitoring, automated alarms, troubleshooting insights |
113 | | - |
114 | | ---- |
115 | | - |
116 | | -## 🔄 How These Services Work Together |
117 | | - |
118 | | -Here's the complete workflow of how a user interacts with this serverless application: |
119 | | - |
120 | | -### **User Visit Flow (Static Content)** |
121 | | -``` |
122 | | -1. User enters URL → 2. CloudFront CDN → 3. S3 Storage → 4. Website Displayed |
123 | | -``` |
124 | | - |
125 | | -**Step-by-step:** |
126 | | -1. **User** types the website URL in their browser |
127 | | -2. **CloudFront** receives the request and checks if content is cached at a nearby edge location |
128 | | -3. If cached, CloudFront serves it instantly; if not, it fetches from **S3** |
129 | | -4. **S3** returns the HTML, CSS, and JavaScript files |
130 | | -5. CloudFront caches and delivers the content to the user's browser |
131 | | -6. **Website** appears on the user's screen |
132 | | - |
133 | | -### **Dynamic Interaction Flow (Form Submission/API Calls)** |
134 | | -``` |
135 | | -1. User Submits Form → 2. API Gateway → 3. Lambda Function → 4. DynamoDB → 5. Response |
136 | | -``` |
137 | | - |
138 | | -**Step-by-step:** |
139 | | -1. **User** fills out a form (e.g., contact form, newsletter signup) and clicks submit |
140 | | -2. **API Gateway** receives the HTTP POST request with form data |
141 | | -3. **API Gateway** triggers the appropriate **Lambda function** based on the endpoint |
142 | | -4. **Lambda function** executes: |
143 | | - - Validates the data |
144 | | - - Processes business logic |
145 | | - - Writes data to **DynamoDB** |
146 | | -5. **DynamoDB** stores the data and confirms success |
147 | | -6. **Lambda** returns a response to **API Gateway** |
148 | | -7. **API Gateway** sends the response back to the website |
149 | | -8. **User** sees a success message |
150 | | - |
151 | | -### **Monitoring & Security** |
152 | | -- **IAM** ensures Lambda has permission to access DynamoDB but nothing else |
153 | | -- **CloudWatch** logs every Lambda execution and API call for debugging |
154 | | -- **CloudFront** provides SSL/TLS encryption and DDoS protection |
155 | | - |
156 | | -### **Real-World Example: Contact Form** |
157 | | -``` |
158 | | -User fills contact form → CloudFront serves page from S3 → |
159 | | -User clicks "Submit" → API Gateway /contact endpoint → |
160 | | -Lambda validateAndStore() function runs → |
161 | | -Data saved to DynamoDB "ContactSubmissions" table → |
162 | | -Lambda returns success → |
163 | | -User sees "Thank you" message |
164 | | -``` |
165 | | - |
166 | | ---- |
167 | | - |
168 | | -## ✨ Key Features |
169 | | - |
170 | | -- **Serverless Architecture**: No infrastructure management required |
171 | | -- **Auto-Scaling**: Automatically handles traffic spikes from 0 to millions of requests |
172 | | -- **Cost-Effective**: Pay only for what you use (no idle server costs) |
173 | | -- **High Availability**: Multi-region deployment with CloudFront (99.99% uptime) |
174 | | -- **Low Latency**: Content cached at 400+ edge locations worldwide |
175 | | -- **Secure**: IAM roles, encryption at rest and in transit, DDoS protection |
176 | | -- **Monitoring**: Real-time metrics and logging with CloudWatch |
177 | | - |
178 | | ---- |
179 | | - |
180 | | -## 📁 Project Structure |
181 | | - |
182 | | -``` |
183 | | -serverless-lambda-project/ |
184 | | -├── css/ |
185 | | -│ └── templatemo-ebook-landing.css # Stylesheet for the demo website |
186 | | -├── img/ |
187 | | -│ └── ... # Demo images |
188 | | -├── js/ |
189 | | -│ └── ... # Demo JavaScript files |
190 | | -├── lambda/ # Lambda function code (if applicable) |
191 | | -│ └── function.py / index.js |
192 | | -├── index.html # Demo static website |
193 | | -└── README.md # This file |
194 | | -``` |
195 | | - |
196 | | ---- |
197 | | - |
198 | | -## 🚀 Deployment Guide |
199 | | - |
200 | | -### Prerequisites |
201 | | -- AWS Account with appropriate permissions |
202 | | -- AWS CLI installed and configured |
203 | | -- Basic knowledge of AWS services |
204 | | - |
205 | | -### Step 1: Set Up S3 Bucket |
206 | | -```bash |
207 | | -# Create S3 bucket for static hosting |
208 | | -aws s3 mb s3://your-bucket-name |
209 | | - |
210 | | -# Upload website files |
211 | | -aws s3 sync . s3://your-bucket-name --exclude "*.md" --exclude ".git/*" |
212 | | - |
213 | | -# Enable static website hosting |
214 | | -aws s3 website s3://your-bucket-name --index-document index.html |
215 | | -``` |
216 | | - |
217 | | -### Step 2: Configure CloudFront Distribution |
218 | | -1. Go to CloudFront console |
219 | | -2. Create distribution with S3 bucket as origin |
220 | | -3. Configure caching behavior and SSL certificate |
221 | | -4. Note the CloudFront domain name |
222 | | - |
223 | | -### Step 3: Create DynamoDB Table |
224 | | -```bash |
225 | | -# Create a table for storing data |
226 | | -aws dynamodb create-table \ |
227 | | - --table-name YourTableName \ |
228 | | - --attribute-definitions AttributeName=id,AttributeType=S \ |
229 | | - --key-schema AttributeName=id,KeyType=HASH \ |
230 | | - --billing-mode PAY_PER_REQUEST |
231 | | -``` |
232 | | - |
233 | | -### Step 4: Deploy Lambda Function |
234 | | -1. Write your Lambda function code (Python, Node.js, etc.) |
235 | | -2. Create IAM role with necessary permissions |
236 | | -3. Deploy function via AWS Console or CLI: |
237 | | -```bash |
238 | | -aws lambda create-function \ |
239 | | - --function-name YourFunctionName \ |
240 | | - --runtime python3.9 \ |
241 | | - --role arn:aws:iam::account-id:role/lambda-role \ |
242 | | - --handler lambda_function.lambda_handler \ |
243 | | - --zip-file fileb://function.zip |
244 | | -``` |
245 | | - |
246 | | -### Step 5: Set Up API Gateway |
247 | | -1. Create REST API in API Gateway |
248 | | -2. Create resources and methods |
249 | | -3. Integrate with Lambda functions |
250 | | -4. Deploy API to a stage |
251 | | -5. Update website to call API endpoints |
252 | | - |
253 | | -### Step 6: Configure IAM Permissions |
254 | | -- Lambda execution role with DynamoDB access |
255 | | -- S3 bucket policy for CloudFront access |
256 | | -- API Gateway invoke permissions |
257 | | - |
258 | | ---- |
259 | | - |
260 | | -## 💡 Learning Objectives |
261 | | - |
262 | | -By exploring this project, you will understand: |
263 | | - |
264 | | -- How to build serverless applications on AWS |
265 | | -- How different AWS services communicate and work together |
266 | | -- Cost optimization with pay-per-use pricing |
267 | | -- Event-driven architecture patterns |
268 | | -- CDN and global content delivery strategies |
269 | | -- NoSQL database design with DynamoDB |
270 | | -- API development with Lambda and API Gateway |
271 | | -- Security best practices with IAM |
272 | | -- Monitoring and logging with CloudWatch |
273 | | - |
274 | | ---- |
275 | | - |
276 | | -## 💰 Cost Estimation |
277 | | - |
278 | | -### AWS Free Tier Includes: |
279 | | -- **Lambda**: 1M free requests/month + 400,000 GB-seconds compute |
280 | | -- **CloudFront**: 50GB data transfer out + 2M HTTP requests |
281 | | -- **DynamoDB**: 25GB storage + 25 read/write capacity units |
282 | | -- **S3**: 5GB storage + 20,000 GET requests + 2,000 PUT requests |
283 | | - |
284 | | -**Estimated Monthly Cost** (beyond free tier for moderate traffic): |
285 | | -- S3: $0.50 - $2 |
286 | | -- Lambda: $1 - $5 |
287 | | -- CloudFront: $3 - $10 |
288 | | -- DynamoDB: $1 - $5 |
289 | | -- **Total**: ~$5-$20/month for thousands of users |
290 | | - |
291 | | -Compare this to traditional EC2 hosting: $20-$100+/month for a single t3.small instance running 24/7. |
292 | | - |
293 | | ---- |
294 | | - |
295 | | -## 🔮 Future Enhancements |
296 | | - |
297 | | -- [ ] Add authentication with Amazon Cognito |
298 | | -- [ ] Implement CI/CD pipeline with AWS CodePipeline |
299 | | -- [ ] Add email notifications with Amazon SES |
300 | | -- [ ] Integrate AWS WAF for advanced security |
301 | | -- [ ] Use AWS SAM or Terraform for Infrastructure as Code |
302 | | -- [ ] Add real-time features with API Gateway WebSockets |
303 | | -- [ ] Implement caching with DynamoDB DAX |
304 | | -- [ ] Add monitoring dashboards with CloudWatch Insights |
305 | | - |
306 | | ---- |
307 | | - |
308 | | -## 📚 Resources |
309 | | - |
310 | | -- [AWS Lambda Documentation](https://docs.aws.amazon.com/lambda/) |
311 | | -- [Amazon S3 Static Website Hosting](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html) |
312 | | -- [CloudFront Developer Guide](https://docs.aws.amazon.com/cloudfront/) |
313 | | -- [DynamoDB Getting Started](https://docs.aws.amazon.com/dynamodb/) |
314 | | -- [API Gateway Documentation](https://docs.aws.amazon.com/apigateway/) |
315 | | -- [AWS Serverless Application Model (SAM)](https://aws.amazon.com/serverless/sam/) |
316 | | - |
317 | | ---- |
318 | | - |
319 | | -## 📄 License & Attribution |
320 | | - |
321 | | -- **Demo Website Template**: Developed by [TemplateMo](https://templatemo.com/) |
322 | | -- The template is used solely for demonstrating AWS serverless architecture |
323 | | -- Please review the TemplateMo license for the website template usage |
324 | | - |
325 | | ---- |
326 | | - |
327 | | -## 📧 Contact |
328 | | - |
329 | | -For questions or feedback about this serverless implementation, please open an issue in this repository. |
330 | | - |
331 | | ---- |
332 | | - |
333 | | -**Built with ☁️ AWS Serverless Services** |
| 12 | +## Problem Solved |
| 13 | +This application simplifies the subscription process for websites, automating email notifications and data management, which enhances user experience and reduces manual efforts for site administrators. |
0 commit comments