Anas El Mhamdi

Create an API in 2 Minutes with AWS Lambda and Serverless

by Anas El Mhamdi

The title might sound like clickbait, but I’ve got video proof to back it up. When your automation workflow reaches a certain level of maturity, you often need custom integrations. Rather than seeing this as overly complicated, it’s entirely feasible to quickly develop one using AWS Lambda and the Serverless framework.

Prerequisites

To get started, you’ll need:

  • An AWS account
  • Node.js installed
  • Serverless framework installed
  • Python, Node, or Go

Implementation Overview

Creating a simple API with AWS Lambda involves a few straightforward steps:

1. Create Your Handler Function

Start by creating an index.py file with a hello_world function that serves as your API handler. This function will process incoming requests and return responses.

Code Example

2. Return Requirements

Your handler functions must return a response with a 200 status code and a body. This is essential for proper HTTP communication.

3. Configure Serverless

Create a serverless.yml file to configure your service. This file specifies:

  • The service name and parameters
  • AWS as the provider
  • The runtime environment (Python, Node, or Go)
  • Handler function references

Serverless Configuration

4. Set Up HTTP Events

Use the “http” Serverless event type to expose your Lambda function as an HTTP endpoint. This allows external services to trigger your function via standard HTTP requests.

5. Enable CORS

Add CORS parameters to your configuration to enable browser-based API calls. This is crucial if you plan to call your API from web applications.

Real-World Application: Newsletter Scraping

I applied this approach to automate lead generation from a French business newsletter (MaddyMoney) that tracks startup fundraising.

The automated workflow:

  1. Subscribe to the newsletter with Gmail
  2. Trigger a POST request to my custom API when a new newsletter arrives
  3. Process the data:
    • Web scraping using BeautifulSoup to extract company information
    • Lead enrichment using Hunter API to find contact details
    • Forward qualified leads to a Lemlist campaign

This automation continues to run smoothly until the website structure changes and requires scraper updates.

Get Started

Ready to build your own API? Check out my public GitHub repository with complete example code to get started.

The combination of AWS Lambda and the Serverless framework makes it incredibly easy to deploy scalable APIs without managing infrastructure. Whether you’re building webhooks, automation workflows, or custom integrations, this approach offers a fast and cost-effective solution.