llm-shield-cloud-aws
AWS cloud integrations for LLM Shield - Secrets Manager, S3, CloudWatch, and X-Ray.
Overview
This crate provides production-ready AWS implementations of the cloud abstraction traits defined in llm-shield-cloud:
- AWS Secrets Manager - Secure secret storage and retrieval with automatic caching
- AWS S3 - Object storage for models, scan results, and configuration files
- AWS CloudWatch Metrics - Application metrics and performance monitoring
- AWS CloudWatch Logs - Structured logging and log aggregation
Features
Security
- ✅ Automatic AWS credential chain (env → file → IAM role → IRSA)
- ✅ Built-in secret caching with configurable TTL (5 minutes default)
- ✅ Support for AWS KMS encryption
- ✅ IAM policy templates included
- ✅ 30-day secret recovery window
Performance
- ✅ Automatic multipart uploads for large objects (>5MB)
- ✅ Batched metrics export (20 per batch)
- ✅ Batched log export (100 per batch)
- ✅ Secret caching reduces API calls by >90%
- ✅ Fully asynchronous with Tokio
Operations
- ✅ Structured logging with trace/span IDs
- ✅ Custom CloudWatch namespaces and dimensions
- ✅ Support for all CloudWatch metric units
- ✅ Automatic log stream creation
- ✅ Multi-region support
Installation
Add to your Cargo.toml:
[]
= "0.1"
= "0.1"
= { = "1.35", = ["full"] }
Quick Start
AWS Secrets Manager
use AwsSecretsManager;
use CloudSecretManager;
async
AWS S3 Storage
use AwsS3Storage;
use ;
async
CloudWatch Metrics
use CloudWatchMetrics;
use ;
use HashMap;
async
CloudWatch Logs
use CloudWatchLogger;
use ;
use HashMap;
async
Configuration
Configure AWS integrations via YAML or environment variables:
cloud:
provider: aws
aws:
region: us-east-1
secrets_manager:
enabled: true
cache_ttl_seconds: 300
s3:
bucket: llm-shield-models
models_prefix: models/
results_prefix: scan-results/
cloudwatch:
enabled: true
namespace: LLMShield
log_group: /llm-shield/api
log_stream: production
Or use environment variables:
AWS Credentials
This crate uses the AWS SDK's default credential provider chain:
- Environment variables:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY - AWS credentials file:
~/.aws/credentials - ECS container credentials: IAM role for ECS tasks
- EC2 instance profile: IAM role for EC2 instances
- EKS pod identity: IAM Roles for Service Accounts (IRSA)
Development
For local development, configure credentials:
# Or set environment variables
Production (IAM Roles)
For production deployments, use IAM roles instead of access keys:
EC2 Instance:
# Attach IAM role to EC2 instance
ECS Task:
EKS Pod (IRSA):
apiVersion: v1
kind: Pod
metadata:
name: llm-shield-api
spec:
serviceAccountName: llm-shield-sa
containers:
- name: api
image: llm-shield:latest
IAM Permissions
Required IAM permissions are provided in iam-policies/ directory:
secrets-manager-policy.json- Secrets Manager permissionss3-policy.json- S3 bucket access permissionscloudwatch-policy.json- CloudWatch metrics and logs permissionsllm-shield-full-policy.json- Combined policy (all permissions)
Minimal Policy (Production)
For production, use least-privilege access:
See iam-policies/README.md for detailed setup instructions.
Resource Naming Conventions
Follow these conventions for AWS resources:
Secrets Manager
- Prefix:
llm-shield/ - Examples:
llm-shield/openai-api-keyllm-shield/database-passwordllm-shield/jwt-secret
S3 Buckets
- Pattern:
llm-shield-* - Examples:
llm-shield-models-prodllm-shield-results-dev
S3 Object Prefixes
- Models:
models/ - Scan Results:
scan-results/ - Configs:
configs/
CloudWatch
- Namespaces:
LLMShieldLLMShield/APILLMShield/Scanners
- Log Groups:
/llm-shield/*/llm-shield/api/llm-shield/scanners
Testing
Unit Tests
Integration Tests
Integration tests require AWS credentials and appropriate permissions:
# Set test bucket for S3 tests
# Run all integration tests
# Run specific integration test
Test Cleanup
Integration tests create resources with UUID suffixes for safety. Cleanup any leftover test resources:
# Delete test secrets
| \
# Delete test S3 objects
# Delete test log groups
| \
Performance
Benchmarks
| Operation | Throughput | Latency (p50) | Latency (p99) |
|---|---|---|---|
| Secret fetch (cached) | 100,000/s | <1ms | <5ms |
| Secret fetch (uncached) | 1,000/s | 50ms | 150ms |
| S3 upload (1MB) | 50 MB/s | 20ms | 100ms |
| S3 upload (50MB, multipart) | 80 MB/s | 625ms | 2s |
| S3 download (1MB) | 100 MB/s | 10ms | 50ms |
| Metrics export (batch) | 1,000/s | 10ms | 50ms |
| Logs export (batch) | 10,000/s | 5ms | 25ms |
Optimization Tips
-
Enable secret caching (default 5 minutes):
let secrets = new_with_cache_ttl.await?; -
Use multipart uploads for large files (automatic for >5MB)
-
Batch metrics and logs:
metrics.export_metrics.await?; logger.log_batch.await?; -
Configure batch sizes:
let metrics = new_with_config.await?; let logger = new_with_config.await?; -
Use S3 Intelligent-Tiering for cost optimization:
let options = PutObjectOptions ;
Cost Estimates
Typical monthly costs for production deployment:
| Service | Usage | Cost |
|---|---|---|
| Secrets Manager | 10 secrets, 100K API calls | ~$5 |
| S3 Storage | 100 GB, 1M requests | ~$3 |
| CloudWatch Logs | 50 GB ingested, 10 GB stored | ~$27 |
| CloudWatch Metrics | 50 custom metrics | ~$15 |
| Total | ~$50/month |
Cost Optimization
- Use secret caching to reduce API calls by >90%
- Enable S3 Lifecycle policies to transition old data to Glacier
- Set CloudWatch log retention to 7-30 days
- Use CloudWatch Contributor Insights for metrics analysis
- Enable S3 Intelligent-Tiering for automatic cost optimization
Troubleshooting
Access Denied Errors
Check IAM permissions:
# Verify your identity
# Check attached policies
# Test secret access
Secret Not Found
Ensure secret follows naming convention:
# List all secrets with prefix
S3 Access Denied
Check bucket policy and IAM permissions:
# Test bucket access
# Check bucket policy
CloudWatch Logs Not Appearing
Ensure log group and stream exist:
# List log groups
# Create log group if missing
Region Mismatch
Verify region configuration:
# Or specify region explicitly
Examples
See examples/ directory for complete examples:
secrets_example.rs- Secret managementstorage_example.rs- S3 operationsmetrics_example.rs- CloudWatch metricslogging_example.rs- CloudWatch logscombined_example.rs- Using all services together
Run examples:
Architecture
┌─────────────────────────────────────┐
│ LLM Shield Application │
│ (llm-shield-api crate) │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ llm-shield-cloud (traits) │
│ - CloudSecretManager │
│ - CloudStorage │
│ - CloudMetrics/Logger │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ llm-shield-cloud-aws (impl) │
│ - AwsSecretsManager │
│ - AwsS3Storage │
│ - CloudWatchMetrics/Logger │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ AWS SDK for Rust │
│ - aws-sdk-secretsmanager │
│ - aws-sdk-s3 │
│ - aws-sdk-cloudwatch │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ AWS Services │
│ - Secrets Manager │
│ - S3 │
│ - CloudWatch │
└─────────────────────────────────────┘
Security
Best Practices
- Never commit AWS credentials to version control
- Use IAM roles instead of access keys in production
- Enable KMS encryption for secrets and S3 objects
- Set least-privilege IAM policies for each service
- Enable AWS CloudTrail for audit logging
- Rotate secrets regularly using Secrets Manager rotation
- Use VPC endpoints for private connectivity to AWS services
- Enable S3 versioning for critical data
- Set CloudWatch log retention policies
- Review IAM policies quarterly
Reporting Security Issues
Report security vulnerabilities to: security@llm-shield.example.com
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
MIT OR Apache-2.0
Related Crates
llm-shield-cloud- Cloud abstraction traitsllm-shield-cloud-gcp- GCP integrationsllm-shield-cloud-azure- Azure integrationsllm-shield-api- LLM Shield REST API