MachaOn-L1 Backend

MachaOn-L1 is one of the projects within the Mach-C MachaOn Project. MachaOn-L1 is specifically designed for building serverless applications on AWS. This project leverages the AWS Serverless Architecture to create scalable, highly available, and event-driven applications using Mach-C's modular libraries, Clean Architecture principles, and the power of AWS cloud services.

MachaOn-L1 provides turnkey solutions for deploying Python-based serverless applications on AWS services like AWS Lambda, API Gateway, DynamoDB, SQS, SNS, and more.

Architecture Overview

The architecture of MachaOn-L1 is built entirely on AWS Serverless services, emphasizing scalability, cost-efficiency, and event-driven design.

Architecture Diagram (High-level Overview):

Marked yellow: service is protected by JWT.

Key AWS Services Used:

  1. API Gateway:
    • Acts as the entry point for HTTP requests.
    • Routes requests to corresponding AWS Lambda handlers.
  2. AWS Lambda:
    • Executes the main application logic using modular handlers.
    • Handles requests for user authentication, registration, and other workflows.
  3. CloudWatch: Logs application events, errors, and metrics for debugging and monitoring.

Infrastructure Diagram

This version of MachaOn requires manual configuration of the API Gateway on the AWS Management Console. Ensure that CORS (Cross-Origin Resource Sharing) is properly enabled for your API by specifying allowed origins, methods, and headers to match your frontend requirements. Additionally, configure the Authorizer (e.g., Lambda Authorizer or Cognito User Pool) to correctly validate authentication tokens and secure your endpoints. Both configurations are essential to ensure proper functionality and secure access to your API resources.

How MachaOn-L1 Works

  1. Predefined Python Handlers: Each AWS Lambda function is defined as a Python handler that maps directly to an event source. For more information you can find on: Python Lambda handlers.
  2. Infrastructure Deployment: MachaOn-L1 uses AWS SAM templates to define all AWS resources, including Lambda functions, DynamoDB tables, and API Gateway endpoints.
  3. Modular Integration: Integrates core Mach-C libraries like interactors, entities, and utilities into the serverless architecture for clean, maintainable code.

How to Deploy

1. Build layers

2. Preparation

  • Create AWS account, install AWS CLI and login.

  • Prepare python and SAM:

> python -m venv venv
> "venv/Scripts/activate.bat"
> pip install aws-sam-cli

3. Build AWS resources

> sam build

2. Deploy the Application

Run the following command to deploy your application:

> sam deploy --parameter-overrides CtpSecretKey=%CTP_SECRET_KEY%

Test

Unit tests

$ pytest --cov-report term --cov=src tests/

References

  1. Sam Deploy