Hello everyone! I recently build a simple serverless web application using AWS .
🛠️ Setting Up the Serverless Backend (Lambda & API Gateway)
This section covers creating the brain of our application – the Lambda function that fetches quotes, and exposing it securely via API Gateway.
🧠 Overview
My goal was to create a web page that, when loaded, displays a new inspirational quote. Building it serverlessly allowed me to dive deep into key AWS services.
- ⚙️ AWS Lambda – Our serverless compute engine for fetching quotes.
- 🌐 Amazon API Gateway – Creates a public HTTP endpoint for our Lambda.
- 🎨 Amazon S3 – Hosts our static website frontend.
- 👁️ AWS CloudWatch – For monitoring and debugging.
- 🔑 AWS IAM – Manages permissions for our services.
Project Structure:
Daily-Quote-Generator/
├── backend/
│ └── lambda_function/
│ └── index.js
└── frontend/
├── index.html
├── style.css
└── script.js
Step 1: Create a Lambda Function
- Go to the AWS Lambda Console.
- Click "Create function".
- Choose "Author from scratch".
-
Function name:
QuoteFetcherFunction
-
Runtime: Select
Node.js 18.x
(or the latest Node.js LTS version available). -
Architecture:
x86_64
(default). - Execution role: Choose "Create a new role with basic Lambda permissions". This automatically creates an IAM role allowing your Lambda to execute.
- Click "Create function".
Step 2: Write Your Lambda Function Code
Once your function is created, navigate to the "Code" tab. Replace the existing content of index.js
with the following code.check the repo for code under Lambda function/
index.js
Step 3: Deploy and Configure Lambda Timeout
- Click the "Deploy" button above the code editor to save your changes.
- Go to the "Configuration" tab.
- In the left menu, click on "General configuration".
- Click "Edit".
- Change the Timeout setting to 30 seconds. This gives your function enough time for network calls, especially when debugging external API issues.
- Click "Save".
Step 4: Create an API Gateway HTTP API
API Gateway is how our frontend will communicate with our Lambda function.
- Go to the AWS API Gateway Console.
- In the left navigation, click on "APIs".
- Click "Create API".
- Choose "HTTP API" and click "Build".
- API name: quote-gen
- Click "Next".
Step 5: Configure Routes and Integration
- Configure routes - optional:
- Method: GET
- Resource path: /quotes (This means your endpoint will look like /prod/quotes)
- Integration target: Select your QuoteFetcherFunction from the dropdown.
- Click "Add route".
- Click "Next".
Step 6: Configure Stages and Deploy
- Configure stages: Leave as default ($default stage mapped to /prod route).
- Click "Next".
- Review and create: Review your settings and click "Create".
Step 7: Get Your API Invoke URL
- Once created, you'll see your Invoke URL (e.g., https://xxxxxxxxx.execute-api.ap-south-1.amazonaws.com/prod/quotes).
- Copy this URL – you will need it for your frontend!
- Till now we connected the API Gateway and lambda function. In Next part we will connect it via frontend and host it as a static website using S3.
📌 Stay tuned for the next part – we’re just getting started!
Top comments (0)