Serverless Function for CPF-based authentication — part of the Torque-OS Mechanics Software platform.
AWS Lambda function that acts as an API Gateway Authorizer:
- Validates the CPF format and check digits
- Queries the database to verify the customer exists and is active
- Returns a signed JWT for consumption of protected API routes
- Runtime: Node.js 20
- Cloud: AWS Lambda + AWS API Gateway
- IaC: Terraform (see mechanics-infra-k8s)
- CI/CD: GitHub Actions
Client
│
└─→ AWS API Gateway
│
├─→ Lambda Authorizer (this repo)
│ │
│ ├─ Validate CPF (format + check digits)
│ ├─ Query RDS → customer exists & active?
│ └─ Return JWT
│
└─→ EKS (mechanics-software API)
src/
handler.js # Lambda entry point
cpf.js # CPF validation logic
db.js # RDS connection and customer lookup
jwt.js # JWT generation
tests/
cpf.test.js
handler.test.js
npm install
npm test| Variable | Description |
|---|---|
DATABASE_URL |
RDS PostgreSQL connection string |
JWT_SECRET |
Secret for signing JWT tokens (min 32 chars) |
JWT_EXPIRATION |
Token expiration (e.g. 3600) |
GitHub Actions pipeline on every push/PR to main:
- Lint + unit tests
- Deploy to AWS Lambda
| Repo | Purpose |
|---|---|
| mechanics-software | Main API application |
| mechanics-infra-k8s | Terraform — VPC + EKS |
| mechanics-infra-db | Terraform — RDS PostgreSQL |
