# vishnugovindu23-cmd/aws-ec2-auto-isolation architecture

> Architecture diagram of the GitHub repository vishnugovindu23-cmd/aws-ec2-auto-isolation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vishnugovindu23-cmd/aws-ec2-auto-isolation
- Repository: https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation

## Overview

This repository automates EC2 containment: GuardDuty, Security Hub, or an analyst request enters a Lambda handler, is normalized and checked, then the isolator preserves evidence before applying quarantine and incident tags. The handler publishes the result to an optional SNS topic. A separate release entry point restores recorded security groups and marks the instance released. The README documents Terraform deployment and trigger wiring; Terraform source was not sampled, so those deployment relationships are based on the README rather than inspected configuration.

Main entry points: [`isolate.py`](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py) (Isolation workflow), [`handler.py`](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/handler.py) (Lambda handlers), [`main.tf`](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/main.tf) (Terraform deployment), [`notify.py`](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/notify.py) (SOC message builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Finding intake"]
  node_handler["Lambda handlers<br/>[handler.py]"]
  node_parser["Finding parser<br/>[finding.py]"]
end

subgraph group_contain["Containment and release"]
  node_isolation["Isolation workflow<br/>[isolate.py]"]
  node_instance["EC2 instance state"]
  node_termination["Termination protection<br/>[isolate.py]"]
  node_snapshots["EBS evidence snapshots<br/>[isolate.py]"]
  node_quarantine["Quarantine security group<br/>[isolate.py]"]
  node_interfaces["Network interface groups<br/>[isolate.py]"]
  node_incidenttags["Incident tags<br/>[isolate.py]"]
  node_restore["Release restoration<br/>[isolate.py]"]
end

subgraph group_notify["SOC notification"]
  node_message["SOC message builder<br/>[notify.py]"]
  node_sns["SNS topic"]
end

subgraph group_deploy["AWS deployment"]
  node_terraform["Terraform deployment<br/>[main.tf]"]
  node_iam["IAM role<br/>[main.tf]"]
  node_logs[("CloudWatch logs")]
end

node_guardduty(("GuardDuty"))
node_securityhub(("Security Hub"))
node_analyst(("Analyst request"))
node_eventbridge["EventBridge rule"]

node_guardduty -->|"raises finding"| node_eventbridge
node_eventbridge -->|"triggers"| node_handler
node_securityhub -.->|"raises finding"| node_handler
node_analyst -.->|"requests isolation"| node_handler
node_handler -->|"parses event"| node_parser
node_handler -->|"isolates instance"| node_isolation
node_handler -->|"publishes result"| node_message
node_handler -->|"releases instance"| node_isolation
node_isolation -->|"describes"| node_instance
node_isolation -->|"enables"| node_termination
node_isolation -->|"creates"| node_snapshots
node_isolation -->|"gets or creates"| node_quarantine
node_isolation -->|"swaps groups"| node_interfaces
node_isolation -->|"records incident"| node_incidenttags
node_isolation -->|"restores groups"| node_restore
node_restore -->|"restores groups"| node_interfaces
node_restore -->|"marks released"| node_incidenttags
node_message -->|"publishes alert"| node_sns
node_terraform -->|"deploys functions"| node_handler
node_terraform -->|"configures trigger"| node_eventbridge
node_terraform -->|"creates topic"| node_sns
node_terraform -->|"creates role"| node_iam
node_terraform -->|"creates log group"| node_logs

click node_handler "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/handler.py"
click node_parser "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/finding.py"
click node_isolation "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py"
click node_termination "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py"
click node_snapshots "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py"
click node_quarantine "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py"
click node_interfaces "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py"
click node_incidenttags "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py"
click node_restore "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py"
click node_message "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/notify.py"
click node_terraform "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/main.tf"
click node_iam "https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/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_handler,node_parser toneBlue
class node_isolation,node_instance,node_termination,node_snapshots,node_quarantine,node_interfaces,node_incidenttags,node_restore toneAmber
class node_message,node_sns,node_analyst toneMint
class node_terraform,node_iam,node_logs toneRose
class node_guardduty,node_securityhub,node_eventbridge toneIndigo
```

## Components

### Finding intake

- [Lambda handlers](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/handler.py): `handler.py`
- [Finding parser](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/finding.py): `finding.py`

### Containment and release

- [Isolation workflow](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py): `isolate.py`
- **EC2 instance state**
- [Termination protection](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py): `isolate.py`
- [EBS evidence snapshots](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py): `isolate.py`
- [Quarantine security group](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py): `isolate.py`
- [Network interface groups](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py): `isolate.py`
- [Incident tags](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py): `isolate.py`
- [Release restoration](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/isolate.py): `isolate.py`

### SOC notification

- [SOC message builder](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/notify.py): `notify.py`
- **SNS topic**

### AWS deployment

- [Terraform deployment](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/main.tf): `main.tf`
- [IAM role](https://github.com/vishnugovindu23-cmd/aws-ec2-auto-isolation/blob/main/main.tf): `main.tf`
- **CloudWatch logs**

### Other components

- **GuardDuty**
- **Security Hub**
- **Analyst request**
- **EventBridge rule**

## Connections

- GuardDuty → EventBridge rule: raises finding (evidence: `README.md`)
- EventBridge rule → Lambda handlers: triggers (evidence: `README.md`)
- Security Hub → Lambda handlers: raises finding (evidence: `README.md`)
- Analyst request → Lambda handlers: requests isolation (evidence: `README.md`)
- Lambda handlers → Finding parser: parses event (evidence: `handler.py`)
- Lambda handlers → Isolation workflow: isolates instance (evidence: `handler.py`)
- Lambda handlers → SOC message builder: publishes result (evidence: `handler.py`)
- Lambda handlers → Isolation workflow: releases instance (evidence: `handler.py`)
- Isolation workflow → EC2 instance state: describes (evidence: `isolate.py`)
- Isolation workflow → Termination protection: enables (evidence: `isolate.py`)
- Isolation workflow → EBS evidence snapshots: creates (evidence: `isolate.py`)
- Isolation workflow → Quarantine security group: gets or creates (evidence: `isolate.py`)
- Isolation workflow → Network interface groups: swaps groups (evidence: `isolate.py`)
- Isolation workflow → Incident tags: records incident (evidence: `isolate.py`)
- Isolation workflow → Release restoration: restores groups (evidence: `isolate.py`)
- Release restoration → Network interface groups: restores groups (evidence: `isolate.py`)
- Release restoration → Incident tags: marks released (evidence: `isolate.py`)
- SOC message builder → SNS topic: publishes alert (evidence: `notify.py`)
- Terraform deployment → Lambda handlers: deploys functions (evidence: `README.md`)
- Terraform deployment → EventBridge rule: configures trigger (evidence: `README.md`)
- Terraform deployment → SNS topic: creates topic (evidence: `README.md`)
- Terraform deployment → IAM role: creates role (evidence: `README.md`)
- Terraform deployment → CloudWatch logs: creates log group (evidence: `README.md`)
