This repository contains two serverless RESTful APIs built using AWS services. Each API is deployed as a separate stack, exemplifying a real-world microservices architecture.
- SUTHUB Technical Assessment - Serverless APIs with AWS SAM
This project consists of two serverless RESTful APIs built using FastAPI and AWS services. These APIs manage age groups and enrollments, leveraging a fully serverless architecture. The APIs are deployed as separate stacks, showcasing a microservices architecture. The project also includes integration tests for both APIs.
The project employs the following AWS services:
- AWS Lambda: Executes code in response to HTTP requests and other triggers.
- Amazon SQS: Provides a message queue for decoupling and scaling microservices.
- Amazon API Gateway: Serves as the single entry point for API requests.
- Amazon DynamoDB: A NoSQL database used for fast and scalable data storage.
AWS SAM (Serverless Application Model) is used for infrastructure as code, enabling streamlined build and deployment processes.
The primary objectives of this project are to:
- Develop two RESTful APIs using FastAPI and AWS services:
- Age Groups API: Manage the creation, retrieval, and deletion of age groups.
- Enrollment API: Handle enrollment requests and check their status.
Credentials
Except the root endpoint, all other endpoints are configured with basic authentication. Each API has its own set of credentials defined as environment variables described in the config.py
file of each project.
As default, the credentials are:
Age Groups API:
- Username:
admin
- Password:
try2crack
Enrollment API:
- Username:
user
- Password:
strongpassword
POST /api/v1/age_groups/
: Create a new age group.DELETE /api/v1/age_groups/{name}
: Delete an age group by name.GET /api/v1/age_groups/
: List all age groups.GET /docs
: Swagger documentation for the API.
API Documentation:
POST /api/v1/enrollments/
: Request enrollment.GET /api/v1/enrollments/{CPF}
: Check enrollment status by CPF (unique identifier).GET /docs
: Swagger documentation for the API.
API Documentation:
- FastAPI: A modern, fast (high-performance), web framework for building APIs with Python, based on standard Python type hints.
- Pydantic: Used for data validation and settings management using Python type annotations.
- Pydantic-settings: Manages application configuration via environment variables, enhancing security and manageability.
- Boto3: The AWS SDK for Python, which allows Python code to interact with AWS services like S3, EC2, and DynamoDB.
The project utilizes a Makefile to streamline the build and deployment processes.
Before you begin, ensure you have the following:
- An AWS account with the necessary permissions.
- AWS SAM CLI installed. Follow the AWS SAM CLI Installation Guide to set it up.
To build and deploy the Age Groups API, run the following command:
make build-age-groups-api-stack && make deploy-age-groups-api-stack
To run integration tests for the Age Groups API, execute:
pytest age-groups-api/
To build and deploy the Enrollment API, run:
make build-enrollment-api-stack && make deploy-enrollment-api-stack
To run integration tests for the Enrollment API, execute:
pytest enrollment-api/