DEV Community

Cover image for 📜Serverless Magic: Build a Daily Quote Generator on AWS (Part 1)
AKASH S
AKASH S

Posted on

📜Serverless Magic: Build a Daily Quote Generator on AWS (Part 1)

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        
Enter fullscreen mode Exit fullscreen mode

Check my repo for Source code

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".

Image description

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

Image description

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".

Image description

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".

Image description

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".

Image description

Step 7: Get Your API Invoke URL

Image description

  • 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)