# shungok/rds_stopper architecture

> Architecture diagram of the GitHub repository shungok/rds_stopper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shungok/rds_stopper
- Repository: https://github.com/shungok/rds_stopper

## Overview

##### Project type and purpose
- This is a serverless, event-driven automation tool whose sole purpose is to stop AWS RDS instances and clusters on a daily schedule, provided they carry a specific tag.

##### File structure
- Top-level files:
- README.md – project overview, install & usage
- lambda/main.py – the Lambda function code that contains the logic to list, filter by tag, and stop RDS resources
- serverless/serverless.yml – Serverless Framework service definition, provider (AWS), function definitions, IAM role statements, environment variables (e.g., TARGET_TAG)
- serverless/events/main.yml – CloudWatch Events Rule definition that invokes the Lambda on a schedule (cron at 00:00 UTC)

##### README for additional insights
- Core AWS services used: Lambda (Python 3.7 + boto3), CloudWatch Events (for scheduling), RDS (DB instances & clusters)
- The Serverless Framework is the deployment mechanism

##### Main components & interactions
a. Components
- CloudWatch Events Rule (scheduled trigger at 0:00 UTC daily)
- AWS Lambda function (main.py)
- AWS RDS (DB Instances & Clusters)
- IAM Role / Permissions (attached to the Lambda)
- Serverless Framework (deployment layer – optional to show)
b. Relationships & data flow
1. CloudWatch Events → triggers → Lambda
2. Lambda (using IAM role permissions) → Describe/List → AWS RDS
3. Lambda → Stop DB Instances/Clusters API calls → AWS RDS
4. Lambda → Logs → CloudWatch Logs
c. Architectural patterns & design principles
- Event-driven serverless architecture
- Single-purpose function (the lambda only handles “stop” logic)
- Infrastructure-as-Code via Serverless Framework
- Tag-based resource selection (extensibility: change tag key/value via environment variable)
d. Technologies/frameworks/libraries
- AWS Lambda (Python 3.7, boto3 1.9.42)
- AWS CloudWatch Events
- AWS RDS API
- Serverless Framework v1.36.3

##### Be detailed—capture each piece
- IAM role with the minimum permissions (rds:Describe*, rds:Stop*, logs:CreateLogStream, logs:PutLogEvents)
- Call out the TARGET_TAG env var from serverless.yml that drives which RDS resources get stopped

Final recommendation:
[Serverless Framework (deploy)]
↓
[CloudWatch Events Rule (cron)] → [Lambda Function (main.py + TARGET_TAG env)] ––> [AWS RDS: Instances & Clusters]
↘
→ [CloudWatch Logs]

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Deployment Layer
    ServerlessService["Serverless Framework Service"]:::deployment
    %% Scheduling Layer
    CloudWatchEvents["CloudWatch Events Rule\n(cron: 00:00 UTC daily)"]:::awsService
    %% Compute Layer
    LambdaFunction["Lambda Function (main.py)\nEnv: TARGET_TAG"]:::awsService
    IAMRole["IAM Role / Permissions\n(rds:Describe*, rds:Stop*, logs:*)"]:::awsService
    %% Data & Logging Layer
    AWSRDS[(AWS RDS:\nInstances & Clusters)]:::database
    CloudWatchLogs["CloudWatch Logs"]:::awsService

    %% Connections
    ServerlessService -.->|"deploys infra"| CloudWatchEvents
    CloudWatchEvents -->|"invokes"| LambdaFunction
    LambdaFunction -->|"Describe & Stop API calls"| AWSRDS
    LambdaFunction -->|"log output"| CloudWatchLogs
    LambdaFunction -->|"uses permissions"| IAMRole

    %% Click Events
    click ServerlessService "https://github.com/shungok/rds_stopper/blob/master/serverless/serverless.yml"
    click CloudWatchEvents "https://github.com/shungok/rds_stopper/blob/master/serverless/events/main.yml"
    click LambdaFunction "https://github.com/shungok/rds_stopper/blob/master/lambda/main.py"
    click README "https://github.com/shungok/rds_stopper/blob/master/README.md"

    %% Styles
    classDef awsService fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef database fill:#90EE90,stroke:#333,stroke-width:1px
    classDef deployment fill:#fff,stroke:#888,stroke-dasharray:5 5,stroke-width:1px
```
