MachcOn-SL-AWS-1 Backend
MachcOn-SL-AWS-1 is one of the projects within the Machc MachaOn Project. MachcOn-SL-AWS-1 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 Machc's modular libraries, Clean Architecture principles, and the power of AWS cloud services.
MachcOn-SL-AWS-1 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 MachcOn-SL-AWS-1 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:
- API Gateway:
- Acts as the entry point for HTTP requests.
- Routes requests to corresponding AWS Lambda handlers.
- AWS Lambda:
- Executes the main application logic using modular handlers.
- Handles requests for user authentication, registration, and other workflows.
- CloudWatch: Logs application events, errors, and metrics for debugging and monitoring.
Infrastructure Diagram
This version of MachcOn 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 MachcOn-SL-AWS-1 Works
- 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.
- Infrastructure Deployment: MachcOn-SL-AWS-1 uses AWS SAM templates to define all AWS resources, including Lambda functions, DynamoDB tables, and API Gateway endpoints.
- Modular Integration: Integrates core Machc libraries like
interactors
,entities
, andutilities
into the serverless architecture for clean, maintainable code.
How to Deploy
1. Build layers
- 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
Running Tests with Coverage
The following command runs all tests in the project using pytest
and generates a coverage report for the src
directory based on the .coveragerc
configuration file:
$ pytest --cov-config=.coveragerc --cov=src