A comprehensive secure agent flow application built with CrewAI and deployed to AWS Bedrock Agent for policy and role management automation.
This project deploys a multi-agent system that:
- Roles Fetcher Agent - Analyzes organizational roles and access details
- Mapping Agent - Maps roles to appropriate permissions and access levels
- Preparer Agent - Structures data for policy creation
- Policy Creator Agent - Generates comprehensive security policies
The system is deployed as:
- AWS Lambda Function - Runs the CrewAI workflow
- AWS Bedrock Agent - Provides conversational interface
- S3 Bucket - Stores API schemas
- CloudWatch - Logging and monitoring
- AWS CLI configured with appropriate permissions
- Terraform >= 1.0
- Python 3.11+
- uv package manager (will be auto-installed if not present)
- OpenAI API Key for CrewAI agents
Your AWS credentials need the following services:
- AWS Lambda (create, update, invoke)
- AWS Bedrock (create agents, invoke models)
- IAM (create roles and policies)
- S3 (create buckets, upload objects)
- CloudWatch (create log groups)
-
Clone and navigate to the project:
git clone <your-repo> cd secure_agent_flow
-
Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh source $HOME/.cargo/env
-
Set up the development environment:
uv sync
-
Configure your variables:
cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your values -
Set your OpenAI API key in terraform.tfvars:
openai_api_key = "your-openai-api-key-here"
-
Deploy the infrastructure:
chmod +x deploy.sh ./deploy.sh
secure_agent_flow/
βββ lambda_handler.py # AWS Lambda handlers
βββ main.py # Local execution entry point
βββ crew.py # CrewAI workflow orchestration
βββ agents.py # Agent definitions
βββ tasks.py # Task definitions
βββ config.py # Configuration management
βββ utils.py # Utility functions
βββ pyproject.toml # uv package configuration
βββ uv.lock # Dependency lock file
βββ main.tf # Main Terraform configuration
βββ variables.tf # Terraform input variables
βββ outputs.tf # Terraform outputs
βββ terraform.tfvars.example # Example configuration
βββ deploy.sh # Deployment script
βββ build_layer.sh # Dependencies layer builder
βββ README.md # This file
This project uses uv for fast and reliable Python package management.
# Install dependencies
uv sync
# Add a new dependency
uv add <package-name>
# Add a development dependency
uv add --dev <package-name>
# Update dependencies
uv sync --upgrade
# Run scripts in the virtual environment
uv run python main.py
# Activate the virtual environment
source .venv/bin/activate
# Install specific versions
uv add "crewai>=0.186.1"# Install all dependencies including dev tools
uv sync
# Install with development dependencies
uv sync --extra dev
# Run tests
uv run pytest
# Run code formatting
uv run black .
# Run type checking
uv run mypy .The following variables can be configured in terraform.tfvars:
| Variable | Description | Default | Required |
|---|---|---|---|
aws_region |
AWS deployment region | us-east-1 |
No |
project_name |
Project name prefix | secure-agent-flow |
No |
environment |
Environment (dev/staging/prod) | dev |
No |
openai_api_key |
OpenAI API key | - | Yes |
lambda_timeout |
Lambda timeout in seconds | 300 |
No |
lambda_memory_size |
Lambda memory in MB | 1024 |
No |
bedrock_model |
Bedrock foundation model | anthropic.claude-3-sonnet-20240229-v1:0 |
No |
aws_region = "us-east-1"
project_name = "secure-agent-flow"
environment = "prod"
openai_api_key = "sk-..."
lambda_timeout = 300
lambda_memory_size = 1024- Go to AWS Console β Amazon Bedrock β Agents
- Find your deployed agent
- Test with sample inputs:
context: Enterprise application with 500 users, role-based access control, Active Directory integration
policy: SOX compliance required, quarterly access reviews, principle of least privilege
# Install dependencies
uv sync
# Set environment variables
export OPENAI_API_KEY="your-key-here"
# Run locally
uv run python main.py
# Or activate the environment and run directly
source .venv/bin/activate
python main.pyimport boto3
import json
lambda_client = boto3.client('lambda')
payload = {
"context_input": "Enterprise system with multiple user roles...",
"policy_requirements": "SOX and GDPR compliance requirements..."
}
response = lambda_client.invoke(
FunctionName='secure-agent-flow-function-dev',
Payload=json.dumps(payload)
)- Function logs:
/aws/lambda/secure-agent-flow-function-{env} - Monitor execution time, memory usage, and errors
- Enable tracing in Lambda configuration for detailed performance insights
-
Import Errors in Lambda
- Ensure all dependencies are in the layer
- Check build_layer.sh execution with uv
- Verify layer compatibility with Python runtime
-
uv Installation Issues
- Install manually:
curl -LsSf https://astral.sh/uv/install.sh | sh - Ensure PATH includes
~/.cargo/bin - Restart terminal after installation
- Install manually:
-
Dependency Conflicts
- Use
uv sync --upgradeto update dependencies - Check
uv.lockfor version conflicts - Use
uv add --resolution highestfor latest versions
- Use
-
Bedrock Model Access
- Ensure model access is enabled in Bedrock console
- Check IAM permissions for bedrock:InvokeModel
# Check uv installation
uv --version
# Validate dependencies
uv sync --dry-run
# Check Terraform plan
terraform plan
# Test Lambda function
aws lambda invoke --function-name secure-agent-flow-function-dev output.json
# View logs
aws logs tail /aws/lambda/secure-agent-flow-function-dev --follow# Run tests with uv
uv run pytest
# Run with coverage
uv run pytest --cov=. --cov-report=html
# Test specific components
uv run pytest tests/test_agents.py# Test deployed Lambda function
aws lambda invoke --function-name secure-agent-flow-function-dev \
--payload '{"context_input":"test","policy_requirements":"test"}' \
response.jsonTo update the deployment:
-
Code Changes:
# Update dependencies if needed uv sync # Redeploy ./deploy.sh
-
Add New Dependencies:
# Add to project uv add new-package # Update build script and redeploy ./deploy.sh
-
Dependency Updates:
# Update all dependencies uv sync --upgrade # Rebuild layer and deploy ./build_layer.sh terraform apply
- Fast installs: 10-100x faster than pip
- Reliable resolution: Consistent dependency resolution
- Lock files: Reproducible builds with uv.lock
- Single binary: No Python required for installation
# Use locked dependencies for production
uv sync --frozen
# Build optimized Lambda layer
./build_layer.sh
# Use specific Python version
uv sync --python 3.11