# amara200169/aws-cost-optimizer architecture

> Architecture diagram of the GitHub repository amara200169/aws-cost-optimizer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amara200169/aws-cost-optimizer
- Repository: https://github.com/amara200169/aws-cost-optimizer

## Overview

AWS Cost Optimizer scans running EC2 instances for low CPU usage, estimates potential savings, and can stop idle instances in explicitly enabled live mode. Users can run the local CLI or view results in the Streamlit dashboard; the scheduled Lambda runs the same workflow and publishes a cost report. Terraform provisions the scheduled AWS deployment and its alerting and failure-handling resources. The runtime scanner and dashboard/handler calls are shown from sampled source; deployment and supporting AWS relationships rely on README documentation.

Main entry points: [`main.tf`](https://github.com/amara200169/aws-cost-optimizer/blob/main/main.tf) (Terraform Infrastructure), [`scanner.py`](https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py) (Local Scanner), [`lambda_src/lambda_handler.py`](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/lambda_handler.py) (Scheduled Handler), [`lambda_src/scanner.py`](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py) (Lambda Scanner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_cli["Local CLI<br/>[scanner.py]"]
  node_dashboard["Streamlit Dashboard<br/>[dashboard.py]"]
  node_lambda["Scheduled Handler<br/>[lambda_handler.py]"]
end

subgraph group_runtime["Scan and Remediation"]
  node_local_scan["Local Scanner<br/>[scanner.py]"]
  node_lambda_scan["Lambda Scanner<br/>[scanner.py]"]
  node_idle_scan["Idle Detection<br/>[scanner.py]"]
  node_lambda_idle["Idle Detection<br/>[scanner.py]"]
  node_cost["Cost Summary<br/>[scanner.py]"]
  node_lambda_cost["Cost Summary<br/>[scanner.py]"]
  node_pricing["Savings Estimate<br/>[scanner.py]"]
  node_lambda_pricing["Savings Estimate<br/>[scanner.py]"]
  node_remediate["Remediation<br/>[scanner.py]"]
  node_lambda_remediate["Remediation<br/>[scanner.py]"]
end

subgraph group_aws["AWS Integrations"]
  node_ec2["EC2"]
  node_cloudwatch_metrics["CloudWatch Metrics"]
  node_cost_explorer["Cost Explorer"]
  node_sns["SNS Alerts"]
  node_eventbridge["EventBridge Schedule"]
  node_sqs["SQS Dead-Letter Queue"]
  node_alarm["CloudWatch Alarm"]
end

subgraph group_deployment["Cloud Deployment"]
  node_terraform["Terraform Infrastructure<br/>[main.tf]"]
  node_state[("Terraform State Store")]
end

node_operator(("Operator"))
node_email(("Email Subscriber"))

node_operator -->|"runs"| node_cli
node_operator -->|"opens"| node_dashboard
node_cli -->|"runs scan"| node_local_scan
node_dashboard -->|"requests metrics"| node_local_scan
node_dashboard -->|"runs live"| node_remediate
node_lambda -->|"calls scan"| node_lambda_scan
node_local_scan -->|"calls"| node_idle_scan
node_local_scan -->|"calls"| node_cost
node_local_scan -->|"calls"| node_remediate
node_idle_scan -->|"estimates savings"| node_pricing
node_lambda_scan -->|"calls"| node_lambda_idle
node_lambda_scan -->|"calls"| node_lambda_cost
node_lambda_scan -->|"calls"| node_lambda_remediate
node_lambda_idle -->|"estimates savings"| node_lambda_pricing
node_idle_scan -->|"lists instances"| node_ec2
node_idle_scan -->|"reads CPU"| node_cloudwatch_metrics
node_cost -->|"reads spend"| node_cost_explorer
node_remediate -->|"stops instances"| node_ec2
node_lambda_idle -->|"lists instances"| node_ec2
node_lambda_idle -->|"reads CPU"| node_cloudwatch_metrics
node_lambda_cost -->|"reads spend"| node_cost_explorer
node_lambda_remediate -->|"stops instances"| node_ec2
node_lambda -->|"publishes report"| node_sns
node_sns -->|"sends alert"| node_email
node_eventbridge -->|"triggers daily"| node_lambda
node_lambda -->|"routes failures"| node_sqs
node_alarm -->|"emails on errors"| node_email
node_terraform -->|"provisions"| node_eventbridge
node_terraform -->|"deploys"| node_lambda
node_terraform -->|"provisions"| node_sns
node_terraform -->|"provisions"| node_sqs
node_terraform -->|"configures"| node_alarm
node_terraform -->|"uses backend"| node_state

click node_cli "https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py"
click node_dashboard "https://github.com/amara200169/aws-cost-optimizer/blob/main/dashboard.py"
click node_lambda "https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/lambda_handler.py"
click node_local_scan "https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py"
click node_lambda_scan "https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py"
click node_idle_scan "https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py"
click node_lambda_idle "https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py"
click node_cost "https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py"
click node_lambda_cost "https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py"
click node_pricing "https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py"
click node_lambda_pricing "https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py"
click node_remediate "https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py"
click node_lambda_remediate "https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py"
click node_terraform "https://github.com/amara200169/aws-cost-optimizer/blob/main/main.tf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_dashboard,node_lambda toneBlue
class node_local_scan,node_lambda_scan,node_idle_scan,node_lambda_idle,node_cost,node_lambda_cost,node_pricing,node_lambda_pricing,node_remediate,node_lambda_remediate toneAmber
class node_ec2,node_cloudwatch_metrics,node_cost_explorer,node_sns,node_eventbridge,node_sqs,node_alarm toneMint
class node_terraform,node_state toneRose
class node_operator,node_email toneIndigo
```

## Components

### User Interfaces

- [Local CLI](https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py): `scanner.py`
- [Streamlit Dashboard](https://github.com/amara200169/aws-cost-optimizer/blob/main/dashboard.py): `dashboard.py`
- [Scheduled Handler](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/lambda_handler.py): `lambda_src/lambda_handler.py`

### Scan and Remediation

- [Local Scanner](https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py): `scanner.py`
- [Lambda Scanner](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py): `lambda_src/scanner.py`
- [Idle Detection](https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py): `scanner.py`
- [Idle Detection](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py): `lambda_src/scanner.py`
- [Cost Summary](https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py): `scanner.py`
- [Cost Summary](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py): `lambda_src/scanner.py`
- [Savings Estimate](https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py): `scanner.py`
- [Savings Estimate](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py): `lambda_src/scanner.py`
- [Remediation](https://github.com/amara200169/aws-cost-optimizer/blob/main/scanner.py): `scanner.py`
- [Remediation](https://github.com/amara200169/aws-cost-optimizer/blob/main/lambda_src/scanner.py): `lambda_src/scanner.py`

### AWS Integrations

- **EC2**
- **CloudWatch Metrics**
- **Cost Explorer**
- **SNS Alerts**
- **EventBridge Schedule**
- **SQS Dead-Letter Queue**
- **CloudWatch Alarm**

### Cloud Deployment

- [Terraform Infrastructure](https://github.com/amara200169/aws-cost-optimizer/blob/main/main.tf): `main.tf`
- **Terraform State Store**

### Other components

- **Operator**
- **Email Subscriber**

## Connections

- Operator → Local CLI: runs (evidence: `README.md`)
- Operator → Streamlit Dashboard: opens (evidence: `README.md`)
- Local CLI → Local Scanner: runs scan (evidence: `scanner.py`)
- Streamlit Dashboard → Local Scanner: requests metrics (evidence: `dashboard.py`)
- Streamlit Dashboard → Remediation: runs live (evidence: `dashboard.py`)
- Scheduled Handler → Lambda Scanner: calls scan (evidence: `lambda_src/lambda_handler.py`)
- Local Scanner → Idle Detection: calls (evidence: `scanner.py`)
- Local Scanner → Cost Summary: calls (evidence: `scanner.py`)
- Local Scanner → Remediation: calls (evidence: `scanner.py`)
- Idle Detection → Savings Estimate: estimates savings (evidence: `scanner.py`)
- Lambda Scanner → Idle Detection: calls (evidence: `lambda_src/scanner.py`)
- Lambda Scanner → Cost Summary: calls (evidence: `lambda_src/scanner.py`)
- Lambda Scanner → Remediation: calls (evidence: `lambda_src/scanner.py`)
- Idle Detection → Savings Estimate: estimates savings (evidence: `lambda_src/scanner.py`)
- Idle Detection → EC2: lists instances (evidence: `scanner.py`)
- Idle Detection → CloudWatch Metrics: reads CPU (evidence: `scanner.py`)
- Cost Summary → Cost Explorer: reads spend (evidence: `scanner.py`)
- Remediation → EC2: stops instances (evidence: `scanner.py`)
- Idle Detection → EC2: lists instances (evidence: `lambda_src/scanner.py`)
- Idle Detection → CloudWatch Metrics: reads CPU (evidence: `lambda_src/scanner.py`)
- Cost Summary → Cost Explorer: reads spend (evidence: `lambda_src/scanner.py`)
- Remediation → EC2: stops instances (evidence: `lambda_src/scanner.py`)
- Scheduled Handler → SNS Alerts: publishes report (evidence: `lambda_src/lambda_handler.py`)
- SNS Alerts → Email Subscriber: sends alert (evidence: `README.md`)
- EventBridge Schedule → Scheduled Handler: triggers daily (evidence: `README.md`)
- Scheduled Handler → SQS Dead-Letter Queue: routes failures (evidence: `README.md`)
- CloudWatch Alarm → Email Subscriber: emails on errors (evidence: `README.md`)
- Terraform Infrastructure → EventBridge Schedule: provisions (evidence: `README.md`)
- Terraform Infrastructure → Scheduled Handler: deploys (evidence: `README.md`)
- Terraform Infrastructure → SNS Alerts: provisions (evidence: `README.md`)
- Terraform Infrastructure → SQS Dead-Letter Queue: provisions (evidence: `README.md`)
- Terraform Infrastructure → CloudWatch Alarm: configures (evidence: `README.md`)
- Terraform Infrastructure → Terraform State Store: uses backend (evidence: `README.md`)
