AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

AWS Infra Documentation Generator & Knowledge Base

The Infrastructure Document Generator is an intelligent automation tool that revolutionizes AWS infrastructure documentation and analysis. By automatically scanning cloud environments, it creates comprehensive, real-time documentation with detailed configuration reports, including dependency maps of resources based on access policies. The tool goes beyond basic documentation by providing actionable insights based on AWS Well-Architected Framework principles, providing reports on Security Best Practices, Comprehensive Analysis and Performance Improvement, enabling organizations to optimize their cloud infrastructure while maintaining accurate documentation with minimal effort.

Architecture

Architecture Diagram

Architecture Workflow

RESOURCE SCANNING PHASE:

  1. Request Resource Information: The process begins when a client sends an initial request to the system to gather information about their AWS infrastructure.

  2. Request Resource Scan: The Resource Scanner component activates and prepares to scan multiple AWS services (Amazon EC2, Amazon DynamoDB, Amazon VPC, Amazon S3, AWS Lambda, etc.). It formulates the appropriate API calls to collect comprehensive infrastructure data.

  3. Authenticate and Access: The system uses the AWS SDK (boto3) to interact with AWS services by making authenticated API requests using the provided credentials. This establishes a valid session for retrieving resource information.

  4. Authorize Access to Query Resources: IAM role permissions are verified to confirm the scanner has the appropriate access rights to query the required AWS services. This serves as a crucial security check before retrieving resource data.

  5. Store Resource Data: The system collects detailed configuration data from various AWS services, including instance details, network configurations, storage settings, and service relationships.

  6. Transfer Resource Data to Cache Storage: The collected data is efficiently moved to local disk cache storage. This enables faster access and reduces repeated API calls to AWS services, improving performance.

  7. Respond with Resource Configuration: The system compiles the collected data into a structured format suitable for client consumption and prepares it for transmission back to the client.

  8. Display Resource Configurations: The formatted resource configuration data is presented to the client through the interface, showing detailed insights into their AWS infrastructure.

DOCUMENTATION GENERATION PHASE:

  1. Request Documentation Generation: The client initiates the documentation process based on the scanned resource data, triggering the Documentation Generator component.

  2. Use Resource Configurations: The system retrieves cached resource data from the scanning phase to serve as the foundation for documentation generation.

  3. Initiate AI Documentation Generation: The system begins the AI-powered documentation process using Amazon Bedrock, preparing the necessary context and prompts for documentation creation.

  4. Authenticate for Bedrock API: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Documentation: IAM permissions are verified to ensure the system is allowed to use Bedrock for generating documentation.

  6. Store Generated AI Documentation: The AI-generated documentation is saved in persistent storage for future reference.

  7. Transfer Documentation to Cache: The generated documentation is copied into cache storage for quicker access and performance.

  8. Return Documentation Response: The system formats and sends the generated documentation back to the client.

  9. Display Documentation: The documentation is presented to the client via the interface in a clear and organized format.

DEPENDENCY MAPPING PHASE:

  1. Request Dependency Analysis: The client initiates the process to analyze and map relationships between AWS resources.

  2. Use Resource Configurations: The system accesses cached resource data from the scanning phase to identify interdependencies among resources.

  3. Initiate Relationship Analysis: The Dependency Mapper processes the resource data to identify and map connections between AWS services.

  4. Authenticate for Bedrock: The system establishes a connection to Amazon Bedrock by making authenticated API requests with valid credentials.

  5. Authorize Access for Dependency Analysis: IAM permissions are verified to ensure the system can use Bedrock for dependency analysis tasks.

  6. Store Dependency Results: The completed dependency analysis results are saved in persistent storage.

  7. Transfer Mappings to Cache: Dependency mapping data is moved into cache storage for faster access and reuse.

  8. Return Dependency Response: The system prepares and sends the dependency analysis results back to the client.

  9. Display Dependency Graph: The final dependency relationships are visualised and shown to the client as an interactive graph, illustrating service connections and resource dependencies.


Features

The Infrastructure Documentation Generator is built in Python with FastAPI for deployment and a React-based user interface for visualization. Its architecture consists of three key modular components:

1. Resource Scanning

  • Discovers and inventories AWS resources across regions
  • Enumerates resources from services like EC2, S3, Lambda, DynamoDB
  • Extracts resource-based policies from applicable services
  • Normalizes and filters fields for consistent output
  • Returns structured JSON data for downstream processing

2. Documentation Generation

  • Leverages Amazon Bedrock (Claude) for AI-powered analysis
  • Produces detailed Markdown documentation with actionable recommendations
  • Implements intelligent chunking for large datasets
  • Supports multiple analysis types (comprehensive, security, cost, performance)
  • Handles retries and errors with exponential backoff

3. Dependency Mapping

  • Analyzes relationships between AWS resources
  • Builds comprehensive service interaction graphs
  • Extracts and processes resource policies and identifiers
  • Constructs uniform ARN representations
  • Generates interactive graph visualizations

Supported AWS Services

The solution currently supports 66 AWS services across multiple categories:

Compute Services

  • EC2: Instances, Security Groups, VPCs, Subnets, Route Tables, Internet Gateways, NAT Gateways, Volumes, Snapshots, Images, Transit Gateways
  • Lambda: Functions, Layers
  • ECS: Clusters
  • EKS: Clusters
  • Batch: Compute Environments, Job Queues, Job Definitions
  • Elastic Beanstalk: Applications, Environments
  • Lightsail: Instances, Load Balancers, Databases, Static IPs, Buckets, Disks

Storage Services

  • S3: Buckets
  • EFS: File Systems
  • FSx: File Systems, Backups
  • Backup: Backup Vaults, Backup Plans

Database Services

  • RDS: DB Instances, DB Clusters, DB Snapshots
  • DynamoDB: Tables
  • ElastiCache: Cache Clusters, Serverless Caches, Subnet Groups, Parameter Groups
  • DocumentDB: DB Clusters, DB Instances
  • Neptune: DB Clusters, DB Instances
  • Redshift: Clusters

Networking Services

  • CloudFront: Distributions
  • Route 53: Hosted Zones
  • API Gateway: REST APIs
  • Direct Connect: Connections, Virtual Interfaces
  • Global Accelerator: Accelerators
  • Network Firewall: Firewalls, Firewall Policies
  • ELB/ALB/NLB: Load Balancers, Target Groups

Security & Identity Services

  • IAM: Users, Groups, Roles, Policies
  • KMS: Keys
  • Secrets Manager: Secrets
  • ACM: Certificates
  • Shield: Protections
  • GuardDuty: Detectors
  • WAF/WAFv2: Web ACLs
  • Macie: Classification Jobs

Application Integration Services

  • SNS: Topics
  • SQS: Queues
  • EventBridge: Rules, Event Buses
  • Step Functions: State Machines
  • MQ: Brokers

Analytics Services

  • Kinesis: Streams
  • Elasticsearch/OpenSearch: Domains, VPC Endpoints
  • OpenSearch Serverless: Collections, VPC Endpoints, Security Policies
  • Athena: Work Groups, Data Catalogs
  • Glue: Databases, Crawlers, Jobs

Machine Learning Services

  • SageMaker: Notebook Instances, Training Jobs, Endpoints
  • Comprehend: Document Classification Jobs, Entity Recognizers
  • Bedrock: Foundation Models, Custom Models, Evaluation Jobs, Provisioned Models
  • Bedrock Agent: Agents, Knowledge Bases

Developer Tools

  • CodeCommit: Repositories
  • CodeBuild: Projects
  • CodePipeline: Pipelines
  • CodeArtifact: Domains
  • ECR: Repositories

IoT Services

  • IoT Core: Things, Policies, Certificates
  • Greengrass: Groups

Media Services

  • MediaConvert: Queues, Presets
  • MediaLive: Channels, Inputs

Migration & Transfer Services

  • DataSync: Tasks, Locations
  • Transfer Family: Servers

Management & Governance Services

  • CloudFormation: Stacks
  • CloudWatch: Metric Alarms
  • Systems Manager: Parameters
  • Organizations: Accounts
  • Resource Groups Tagging API: Resource Tag Mappings
  • Cost Explorer: Cost Category Definitions
  • Savings Plans: Savings Plans

Business Applications

  • WorkMail: Organizations
  • WorkSpaces: Workspaces

Resource-Based Policy Support

The solution extracts and analyzes resource-based policies for the following services:

  • Lambda: Function resource policies
  • SQS: Queue access policies
  • SNS: Topic access policies
  • S3: Bucket policies
  • EC2: Instance profile policies (IAM roles attached to instances)
  • Glue: Resource policies
  • EventBridge: Resource policies
  • Step Functions: Resource policies
  • EFS: File system policies
  • CloudWatch: Resource policies
  • KMS: Key policies
  • API Gateway: Resource policies

Amazon Bedrock Configuration

Supported Regions

The solution uses us-east-1 as the default region for Amazon Bedrock.

Model Configuration

The solution uses Claude 3.7 Sonnet (us.anthropic.claude-3-7-sonnet-20250219-v1:0) as the default model.

Prerequisites

Before using the solution, ensure Claude 3.7 Sonnet is enabled in us-east-1:

  1. Go to Amazon Bedrock console in us-east-1
  2. Navigate to "Model access" in the left sidebar
  3. Request access to "Claude 3.7 Sonnet" if not already enabled
  4. Wait for approval (usually immediate for most accounts)

AWS Authentication Best Practices

Recommended Approach: AWS SSO/IAM Identity Center

For the most secure and convenient authentication, use AWS SSO (IAM Identity Center):

  1. Configure AWS SSO Profile:

    aws configure sso
    • Follow the prompts to set up your SSO profile
    • Choose a profile name (e.g., infradocgen-dev)
  2. Login and Use:

    aws sso login --profile infradocgen-dev
    export AWS_PROFILE=infradocgen-dev

Security Best Practices

  • Never commit AWS credentials to version control
  • Use least privilege principle - only grant necessary Bedrock permissions
  • Rotate access keys regularly (if using IAM users)
  • Enable MFA on your AWS account
  • Use temporary credentials when possible (SSO preferred)

Bedrock Guardrails and Security Best Practices

Setting Up Bedrock Guardrails

Bedrock Guardrails help protect your application from harmful content and prompt injection attacks. Here's how to implement them:

1. Create a Guardrail Configuration

importboto3bedrock=boto3.client('bedrock')
# Create guardrailguardrail_response=bedrock.create_guardrail(
name='infradocgen-guardrail',
description='Guardrail for InfraDocGen infrastructure code generation',
topicPolicyConfig={
'topicsConfig': [
{
'name': 'Infrastructure Security',
'definition': 'Prevent generation of insecure infrastructure configurations',
'examples': [
'Do not create resources with public access unless explicitly required',
'Always use encryption for data at rest and in transit'
],
'type': 'DENY'
}
]
},
contentPolicyConfig={
'filtersConfig': [
{
'type': 'SEXUAL',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'VIOLENCE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'HATE',
'inputStrength': 'HIGH',
'outputStrength': 'HIGH'
},
{
'type': 'INSULTS',
'inputStrength': 'MEDIUM',
'outputStrength': 'MEDIUM'
}
]
},
wordPolicyConfig={
'wordsConfig': [
{
'text': 'admin123'
},
{
'text': 'password123'
}
],
'managedWordListsConfig': [
{
'type': 'PROFANITY'
}
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{
'type': 'EMAIL',
'action': 'BLOCK'
},
{
'type': 'PHONE',
'action': 'BLOCK'
},
{
'type': 'AWS_ACCESS_KEY',
'action': 'BLOCK'
},
{
'type': 'AWS_SECRET_KEY',
'action': 'BLOCK'
}
]
}
)

2. Apply Guardrails to Model Invocation

importboto3importjsondefinvoke_model_with_guardrails(prompt, guardrail_id, guardrail_version):
bedrock_runtime=boto3.client('bedrock-runtime')
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
})
response=bedrock_runtime.invoke_model(
body=body,
modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
accept='application/json',
contentType='application/json',
guardrailIdentifier=guardrail_id,
guardrailVersion=guardrail_version
)
returnresponse

Prompt Injection Prevention Techniques

Input Validation and Sanitization

importrefromtypingimportListclassPromptValidator:
def__init__(self):
# Common prompt injection patternsself.injection_patterns= [
r'ignore\s+previous\s+instructions',
r'forget\s+everything',
r'new\s+instructions?:',
r'system\s*:',
r'assistant\s*:',
r'human\s*:',
r'<\s*system\s*>',
r'<\s*\/\s*system\s*>',
r'pretend\s+to\s+be',
r'act\s+as\s+if',
r'roleplay\s+as'
]
defvalidate_input(self, user_input: str) ->tuple[bool, List[str]]:
"""Validate user input for potential prompt injection attempts"""violations= []
# Check for injection patternsforpatterninself.injection_patterns:
ifre.search(pattern, user_input.lower()):
violations.append(f"Potential injection pattern detected: {pattern}")
# Check for excessive special charactersspecial_char_ratio=len(re.findall(r'[<>{}[\]()"]', user_input)) /len(user_input)
ifspecial_char_ratio>0.3:
violations.append("Excessive special characters detected")
# Check input lengthiflen(user_input) >10000:
violations.append("Input exceeds maximum length")
returnlen(violations) ==0, violationsdefsanitize_input(self, user_input: str) ->str:
"""Sanitize user input by removing potentially harmful content"""# Remove HTML-like tagssanitized=re.sub(r'<[^>]*>', '', user_input)
# Remove excessive whitespacesanitized=re.sub(r'\s+', ' ', sanitized).strip()
# Limit lengthsanitized=sanitized[:5000]
returnsanitized

Implementation Best Practices

1. Environment Configuration

# config.pyimportosfromdataclassesimportdataclass@dataclassclassSecurityConfig:
enable_guardrails: bool=Trueguardrail_id: str=os.getenv('BEDROCK_GUARDRAIL_ID', '')
guardrail_version: str=os.getenv('BEDROCK_GUARDRAIL_VERSION', 'DRAFT')
max_input_length: int=5000enable_input_validation: bool=Trueenable_response_validation: bool=Truelog_security_events: bool=True

2. Logging and Monitoring

importloggingfromdatetimeimportdatetimeclassSecurityLogger:
def__init__(self):
self.logger=logging.getLogger('infradocgen_security')
self.logger.setLevel(logging.INFO)
handler=logging.StreamHandler()
formatter=logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
deflog_validation_failure(self, input_text: str, violations: List[str]):
self.logger.warning(
f"Input validation failed - Violations: {violations} - "f"Input preview: {input_text[:100]}..."
)
deflog_guardrail_block(self, reason: str):
self.logger.warning(f"Bedrock Guardrail blocked request: {reason}")
deflog_successful_generation(self, input_length: int, output_length: int):
self.logger.info(
f"Successful code generation - Input: {input_length} chars, "f"Output: {output_length} chars"
)

Required Additional IAM Permissions for Guardrails

Add these permissions to your IAM policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateGuardrail",
"bedrock:GetGuardrail",
"bedrock:UpdateGuardrail",
"bedrock:ListGuardrails"
],
"Resource": [
"arn:aws:bedrock:*:*:foundation-model/anthropic.claude-3-7-sonnet-*",
"arn:aws:bedrock:*:*:guardrail/*"
]
}
]
}

Local Development Setup

Backend API

# Clone the repository
git clone https://gitlab.aws.dev/vashivij/aws-infra-doc-generator-and-kb.git
cd aws-infra-doc-generator-and-kb
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
# Configure AWS credentials (optional for CLI testing)
aws configure
# Install dependencies
pip install -r requirements.txt
# Run the API
uvicorn main:app --reload

Frontend UI

# Navigate to UI foldercd infra-ui
# Create environment fileecho"VITE_API_BASE_URL=http://127.0.0.1:8000"> .env
# Install dependencies
npm install
# Start development server
npm run dev

API Testing

You can test the API using the Swagger UI provided by FastAPI.

Swagger UI Endpoint: http://127.0.0.1:8000/docs


Frontend Application

A React application using AWS Cloudscape Design components to display AWS resources from infrastructure analysis.

Features

  • Displays AWS resources organized by service and region
  • AI-powered infrastructure analysis and documentation
  • Interactive dependency graphs with drag-and-drop functionality
  • Real-time progress tracking for analysis operations
  • Clean, responsive UI using AWS Cloudscape Design components
  • Context API for data fetching and state management

Prerequisites

  • Node.js (v20 or later)
  • npm or yarn
  • Running backend API

Usage

  1. Start the backend API server
  2. Launch the frontend application
  3. Navigate to http://localhost:3000
  4. Use the interface to scan AWS infrastructure and generate documentation

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages