This example shows how to build and deploy a simple serverless API using AWS Lambda, API Gateway, and AWS SAM (Serverless Application Model). The API fetches a list of todos from a public endpoint and returns them via an HTTP GET request.


Project Structure

Here’s a quick overview of the project’s key components:

  • functions/: Contains the Lambda function ListTodos.mjs, which fetches todo items from a public API using Axios.
  • tests/: Contains a Jest test to ensure the function returns items with a 200 status code.
  • layers/: Optional shared layer for common dependencies (e.g., axios), defined under nodejs/package.json.
  • template.yaml: AWS SAM template that defines the infrastructure:
    • Lambda function (ListTodosFunction)
    • API Gateway (/posts)
    • Shared Layer

How It Works

When a client makes a GET request to /todos, the Lambda function is triggered, fetches data from https://jsonplaceholder.typicode.com/todos?_limit=3, and returns it as JSON.

This setup demonstrates the basics of building and testing serverless APIs using modern tooling.


Project Repository: https://github.com/OmarMakled/aws-sam-lambda-api

A solid starting point for anyone learning AWS SAM or wanting to build quick APIs with Node.js and Lambda.