Skip to content

Autonomous threat containment agent built with AWS native services

License

Notifications You must be signed in to change notification settings

lshw54/aws-threat-containment-agent-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AWS Threat Containment Agent

AWS License GuardDuty Step Functions

A cost-effective, serverless autonomous threat containment system built on AWS. This POC demonstrates how to automatically detect, analyze, and respond to security threats using native AWS servicesβ€”inspired by the agentic AI patterns announced at AWS re:Invent 2025.

Architecture

🎯 Overview

This project implements an autonomous security response pipeline that:

  1. Detects threats via Amazon GuardDuty
  2. Enriches findings with correlated signals from Security Hub
  3. Evaluates containment policies (Cedar-inspired rules)
  4. Checks incident memory for similar past events
  5. Executes containment actions (isolation, forensic snapshots)
  6. Notifies the security team via SNS
  7. Records episodes for future learning

Why This Project?

After attending AWS re:Invent 2025 and seeing the Amazon Bedrock AgentCore announcements, I wanted to validate the agentic security patterns without committing to expensive managed services upfront. This POC cost approximately $0.15 to build and test.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     GuardDuty (Sample Findings for Testing)             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              EventBridge Rule (severity >= 4 filter)                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Step Functions State Machine                         β”‚
β”‚                                                                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚ Enrich  │──▢│ Check   │──▢│Evaluate │──▢│ Execute Containment β”‚   β”‚
β”‚   β”‚ Finding β”‚   β”‚ Memory  β”‚   β”‚ Policy  β”‚   β”‚  (Parallel Actions) β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                       β”‚               β”‚
β”‚                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”‚                      β–Ό                                                β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚              β”‚  Notify SOC  │──▢│Record Episodeβ”‚                     β”‚
β”‚              β”‚    (SNS)     β”‚   β”‚  (DynamoDB)  β”‚                     β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • AWS Account with Administrator access
  • AWS CLI v2 configured (aws configure)
  • Bash shell (Linux/macOS/WSL)
  • Python 3.9+ (for test scripts)

One-Command Deployment

# Clone the repository
git clone https://github.com/lshw54/aws-threat-containment-agent-demo.git
cd aws-threat-containment-agent-demo

# Deploy all resources
chmod +x deploy.sh
./deploy.sh

The deployment script will create:

  • 1 DynamoDB table (incident memory)
  • 1 SNS topic (SOC notifications)
  • 7 Lambda functions (containment logic)
  • 1 Step Functions state machine (orchestration)
  • 1 EventBridge rule (GuardDuty trigger)
  • Required IAM roles and policies

Test the Pipeline

# Generate sample findings and verify execution
./scripts/test.sh

Expected output:

πŸ§ͺ Testing Pipeline...

1️⃣ Generating sample findings...
   βœ“ Sample findings generated

2️⃣ Waiting 60 seconds for pipeline execution...

3️⃣ Checking executions...
+------------------------------------------+-----------+
|                   Name                   |  Status   |
+------------------------------------------+-----------+
|  abc123-def456-...                       | SUCCEEDED |
+------------------------------------------+-----------+

4️⃣ Checking DynamoDB...
Count: 1

βœ… Test complete! Check your email for SNS notifications.

πŸ“ Project Structure

aws-threat-containment-agent/
β”œβ”€β”€ lambda/
β”‚   β”œβ”€β”€ enrich_finding.py           # Enrich GuardDuty findings
β”‚   β”œβ”€β”€ check_incident_memory.py    # Query similar past incidents
β”‚   β”œβ”€β”€ evaluate_containment_policy.py  # Cedar-inspired policy engine
β”‚   β”œβ”€β”€ snapshot_for_forensics.py   # Create EBS snapshots
β”‚   β”œβ”€β”€ isolate_instance.py         # Apply isolation security group
β”‚   β”œβ”€β”€ notify_soc.py               # Send SNS notifications
β”‚   └── record_episode.py           # Store incident in DynamoDB
β”œβ”€β”€ infrastructure/
β”‚   └── state_machine.json          # Step Functions definition
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ generate_sample_findings.py # Generate test findings
β”‚   β”œβ”€β”€ test.sh                     # End-to-end test script
β”‚   └── verify_pipeline.py          # Verification utility
β”œβ”€β”€ docs/
β”‚   └── architecture.png            # Architecture diagram
β”œβ”€β”€ deploy.sh                       # One-click deployment
β”œβ”€β”€ cleanup.sh                      # Resource cleanup
β”œβ”€β”€ diagnose.sh                     # Troubleshooting utility
└── README.md

πŸ”§ Configuration

EventBridge Filter

The default rule triggers on GuardDuty findings with severity >= 4 (Medium and above):

{
  "source": ["aws.guardduty"],
  "detail-type": ["GuardDuty Finding"],
  "detail": {
    "severity": [{"numeric": [">=", 4]}]
  }
}

Finding Type Severities

Finding Type Severity Triggers Pipeline?
UnauthorizedAccess:EC2/SSHBruteForce 2.0 ❌ No
Recon:EC2/PortProbeUnprotectedPort 5.0 βœ… Yes
Backdoor:EC2/C&CActivity.B 8.0 βœ… Yes
CryptoCurrency:EC2/BitcoinTool.B 8.0 βœ… Yes

Policy Rules

The policy engine (evaluate_containment_policy.py) implements these rules:

Policy Condition Action
Sample Finding Safe Mode isSampleFinding == true Forensics only, no isolation
High False Positive falsePositiveRate > 30% Require human approval
Uncorrelated High Severity severity >= 7 AND correlationScore < 1 Require human approval
Default All checks pass Permit all actions

πŸ’° Cost Estimate

Component Monthly Cost (Low Volume)
GuardDuty (sample findings) $0
EventBridge ~$0 (free tier)
Step Functions ~$0.025 per 1K transitions
Lambda ~$0 (free tier)
DynamoDB (on-demand) ~$1.25 per 1M writes
SNS ~$0 (free tier)
Total for POC testing ~$0.15

πŸ” Troubleshooting

Run the diagnostic script to identify issues:

./diagnose.sh

Common Issues

EventBridge not triggering Step Functions:

# Check if rule exists and is enabled
aws events describe-rule --name ThreatContainmentTrigger

# Check IAM role permissions
aws iam get-role-policy \
  --role-name ThreatContainmentEventBridgeRole \
  --policy-name InvokeStepFunctions

No sample findings generated:

# Verify GuardDuty is enabled
aws guardduty list-detectors

# Generate high-severity findings
aws guardduty create-sample-findings \
  --detector-id YOUR_DETECTOR_ID \
  --finding-types "Backdoor:EC2/C&CActivity.B"

πŸš€ Future Enhancements: Path to AgentCore

This POC validates patterns that map directly to Amazon Bedrock AgentCore (announced at re:Invent 2025):

Current Implementation AgentCore Upgrade
Lambda policy engine AgentCore Policy (Cedar + natural language)
DynamoDB queries AgentCore Memory (semantic search)
Direct Lambda invocation AgentCore Gateway (MCP tool discovery)
No quality monitoring AgentCore Evaluations (continuous assessment)

🧹 Cleanup

Remove all created resources:

chmod +x cleanup.sh
./cleanup.sh

Note: GuardDuty is NOT disabled by the cleanup script. To disable:

aws guardduty delete-detector --detector-id YOUR_DETECTOR_ID

πŸ“š Related Resources

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Autonomous threat containment agent built with AWS native services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published