# aws-samples/amazon-guardduty-automated-response-sample architecture

> Architecture diagram of the GitHub repository aws-samples/amazon-guardduty-automated-response-sample, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aws-samples/amazon-guardduty-automated-response-sample
- Repository: https://github.com/aws-samples/amazon-guardduty-automated-response-sample

## Overview

##### Project type and purpose
- This is a serverless, event-driven security automation solution for AWS (an AWS “full-stack” cloud application without a traditional UI).
- It listens for Amazon GuardDuty findings (EC2, S3, IAM) and automatically quarantines or remediates affected resources via AWS Step Functions and Lambda.

##### File structure
- Top-level:
- `template.yml` (SAM/CloudFormation)
- `src/quarantine/` (Lambda handler + plugin framework + resource abstractions)
- `events/` (sample GuardDuty event JSON)
- `doc/architecture.drawio` & `.png` (reference architecture)
- The Lambda code uses a plugin-based design (`plugins/01_…11`) to sequence discrete quarantine steps.
- Resource wrappers (`resources/`) encapsulate AWS API calls (EC2, S3, SNS, SSM, ASG, ELB, IAM).

##### README for additional insights
- GuardDuty → EventBridge → Step Functions → Lambda → plugin sequence
- On EC2 findings: snapshot volumes, tag instance, detach from ASG, isolate network, etc.
- On S3 findings: block public access via PutPublicAccessBlock
- On IAM findings: attach revoke-session policy

##### Final advice
- Essential elements: event sources, orchestration, compute, data stores, and resource remediation.
- Reference `doc/architecture.drawio` as a starting template, then tailor it to highlight the plugin-based quarantining and resource abstractions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Trigger
    GuardDuty["Amazon GuardDuty"]:::external

    subgraph "AWS Cloud" 
        direction TB
        EventBridge["Amazon EventBridge"]:::aws
        StepFunctions["AWS Step Functions"]:::aws
        SSM["AWS Systems Manager Session Manager"]:::aws
        subgraph "Remediated AWS Resources"
            direction TB
            EC2["EC2 Instance"]:::aws
            S3Resource["S3 Bucket"]:::aws
            IAM["IAM User/Role"]:::aws
        end
    end

    subgraph "Application Boundary"
        direction TB
        Lambda["Quarantine Lambda\n(plugin pipeline)"]:::app
        subgraph "Plugin-based Quarantine Pipeline"
            direction TB
            AP1["abstract_plugin.py"]:::app
            P1["01_console_screenshot.py"]:::app
            P2["02_capture_metadata.py"]:::app
            P3["03_termination_protection.py"]:::app
            P4["04_shutdown_behavior.py"]:::app
            P5["05_preserve_volumes.py"]:::app
            P6["06_tag_instance.py"]:::app
            P7["07_snapshot_volumes.py"]:::app
            P8["08_command_output.py"]:::app
            P9["09_detach_from_asg.py"]:::app
            P10["10_deregister_instance.py"]:::app
            P11["11_isolate_instance.py"]:::app
        end
        subgraph "Resource Abstraction Layer"
            direction TB
            R1["ec2.py"]:::app
            R2["s3.py"]:::app
            R3["autoscaling.py"]:::app
            R4["elb.py"]:::app
            R5["elbv2.py"]:::app
            R6["sns.py"]:::app
            R7["ssm.py"]:::app
        end
        subgraph "Utilities & Config"
            direction TB
            C1["constants.py"]:::app
            C2["schemas.py"]:::app
            C3["utils.py"]:::app
        end
    end

    subgraph "Data Stores"
        direction TB
        S3["S3 Bucket (artifacts)"]:::data
    end

    subgraph "Deployment"
        direction TB
        SAM["SAM/CloudFormation\ntemplate.yml"]:::infra
    end

    GuardDuty -->|emits finding| EventBridge
    EventBridge -->|triggers| StepFunctions
    StepFunctions -->|invokes| Lambda
    Lambda -->|uploads artifacts| S3
    Lambda -->|calls AWS APIs| R1 & R2 & R3 & R4 & R5 & R6 & R7
    R1 --> EC2
    R2 --> S3Resource
    R3 --> EC2
    R4 --> EC2
    R5 --> EC2
    R6 --> SNS
    R7 --> SSM
    Lambda -->|isolates/terminates| EC2
    Lambda -->|revokes sessions| IAM
    Lambda -->|blocks access| S3Resource

    SAM -->|deploys| EventBridge
    SAM -->|deploys| StepFunctions
    SAM -->|deploys| Lambda
    SAM -->|creates| S3
    SAM -->|configures| SSM

    %% Click Events
    click Lambda "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/lambda_handler.py"
    click AP1 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/abstract_plugin.py"
    click P1 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/01_console_screenshot.py"
    click P2 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/02_capture_metadata.py"
    click P3 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/03_termination_protection.py"
    click P4 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/04_shutdown_behavior.py"
    click P5 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/05_preserve_volumes.py"
    click P6 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/06_tag_instance.py"
    click P7 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/07_snapshot_volumes.py"
    click P8 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/08_command_output.py"
    click P9 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/09_detach_from_asg.py"
    click P10 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/10_deregister_instance.py"
    click P11 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/plugins/11_isolate_instance.py"
    click R1 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/resources/ec2.py"
    click R2 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/resources/s3.py"
    click R3 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/resources/autoscaling.py"
    click R4 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/resources/elb.py"
    click R5 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/resources/elbv2.py"
    click R6 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/resources/sns.py"
    click R7 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/resources/ssm.py"
    click C1 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/constants.py"
    click C2 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/schemas.py"
    click C3 "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/src/quarantine/utils.py"
    click SAM "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/template.yml"
    click GuardDuty "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/events/guardduty_ec2_event.json"
    click GuardDuty "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/events/guardduty_s3_event.json"
    click GuardDuty "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/events/guardduty_iam_event.json"
    click SAM "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/doc/architecture.drawio"
    click SAM "https://github.com/aws-samples/amazon-guardduty-automated-response-sample/blob/main/doc/architecture.png"

    %% Styles
    classDef aws fill:#f7c948,stroke:#e58900,color:#000
    classDef app fill:#93c5fd,stroke:#3b82f6,color:#000
    classDef data fill:#a7f3d0,stroke:#047857,color:#000
    classDef infra fill:#d1d5db,stroke:#6b7280,color:#000
    classDef external fill:#e5e7eb,stroke:#6b7280,color:#000
```
