AWS Secrets Manager & Parameter Store: Security Best Practices
A comprehensive technical guide comparing AWS Secrets Manager and Systems Manager Parameter Store, demonstrating when to use each service with real-world implementation patterns.
Engineers working with AWS face a common dilemma: choosing between Secrets Manager and Parameter Store for secrets management. While both services store sensitive data, they serve different purposes and come with different cost structures. This guide provides technical decision criteria, complete implementation patterns, and real-world lessons learned.
Understanding the Services
Before diving into implementation, let's establish the technical differences between these services.
Service Comparison
Key Technical Insight: Parameter Store with SecureString uses KMS encryption and provides free basic secrets management. Secrets Manager adds automatic rotation, native RDS integration, and built-in versioning with staging labels.
Decision Framework
Use this technical decision tree to choose the right service:
Cost Analysis Example:
- 10 static API keys → Parameter Store Standard: $0/month
- 5 RDS passwords with rotation → Secrets Manager: $2.00/month
- 20 configuration values → Parameter Store Standard: $0/month
- Total: 10.00/month if everything was in Secrets Manager
Cross-Account Secret Sharing
One of the most common requirements is sharing secrets between AWS accounts. Here's the complete implementation pattern.
Architecture Overview
Implementation - Account A (Secret Owner)
Implementation - Account B (Secret Consumer)
Warning: Common Pitfall: Forgetting to grant KMS decrypt permission in Account B. The secret retrieval will fail with "AccessDeniedException" even if the Secrets Manager policy is correct.
Tip: Use CloudTrail to check for KMS API calls with error codes. Look for "Decrypt" operations that failed with "AccessDenied".
Parameter Store Reference Pattern
You can standardize on Parameter Store API while storing actual secrets in Secrets Manager:
Application code only needs Parameter Store SDK:
Benefit: Simplified application code, single API surface area, easier migration path between services.
Container Secrets Injection
There are multiple patterns for injecting secrets into containers, each with different trade-offs.
Pattern A: Environment Variable Injection (ECS)
This is the native ECS approach - secrets are injected at container startup.
Raw Task Definition JSON:
Warning: Critical Limitation: Secrets are injected ONLY at container startup. Rotated secrets require container restart (new task launch).
Pattern B: Runtime Retrieval with Caching
For applications that need to handle rotation without restarts:
Cost Analysis:
- Startup injection: 1 API call per container start (~$0.05/10,000 calls)
- Runtime retrieval with 5-min cache:
288 API calls/day per container ($1.44/month per container) - Runtime retrieval per request: Potentially thousands of API calls (expensive, not recommended)
Pattern C: AWS Parameters and Secrets Lambda Extension
For Lambda functions, use the extension for built-in caching:
Benefits:
- Built-in caching (reduces API calls by ~90%)
- No code changes to application logic for caching
- Supports both Secrets Manager and Parameter Store
Deployment:
Tip: Cost Savings: Lambda extension reduces API calls by 99%. Costs drop from 0.05/month for high-traffic functions.
EKS Secrets with CSI Driver
For Kubernetes workloads on EKS, use the Secrets Store CSI Driver for native integration.
Architecture Setup
SecretProviderClass Configuration
Pod Configuration with IRSA
IAM Role for Pod Identity
Key Difference - IRSA vs Pod Identity:
- IRSA (older method): Requires OIDC provider setup, works with EKS 1.17+
- Pod Identity (newer method, 2024+): Simplified setup, better performance, requires EKS 1.24+
Secret Rotation Implementation
Automated rotation is one of the key benefits of Secrets Manager. Here's how to implement it correctly.
Rotation Flow
Lambda Rotation Function - RDS MySQL
CDK Setup for Rotation
For RDS databases with built-in support:
For custom applications:
Warning: Common Pitfalls:
- Network Access: Lambda needs VPC access to reach database. Configure VPC subnets correctly.
- Timeout: Default 3 seconds is too short. Set to 5 minutes for rotation.
- Permissions: Lambda needs both read and write to secret, plus KMS decrypt/encrypt.
- Idempotency: Always check if AWSPENDING version exists before creating new one.
- Connection Pooling: Open connections using old password won't automatically get new password. Applications should handle connection refresh.
Alternating Users Strategy
For zero-downtime rotation in high-availability applications:
Architecture:
- Two database users:
app_user_aandapp_user_b - Both users have identical permissions
- Rotation alternates which user's password is updated
- Application always has one valid credential during rotation
Benefits:
- No downtime window
- Active connections continue working during rotation
- Suitable for applications that can't handle connection refresh
Trade-off: Requires superuser credentials in separate secret to clone users.
Multi-Region Secrets Replication
For disaster recovery scenarios, Secrets Manager supports automatic replication.
Primary Secret with Replication
ARN Structure:
- Primary:
arn:aws:secretsmanager:us-east-1:123456789012:secret:prod/database-credentials-AbCdEf - Replica:
arn:aws:secretsmanager:us-west-2:123456789012:secret:prod/database-credentials-AbCdEf
Key Points:
- Secret suffix (
-AbCdEf) is identical across regions - Replication is automatic and near real-time
- Rotation in primary region propagates to replicas
- Each replica is billed as separate secret ($0.40/month each)
- Replicas are read-only, updates must happen in primary region
Disaster Recovery with Failover
Cost Optimization Alternative
Instead of replication, use cross-region secret access (higher latency, lower cost):
Trade-off: Saves $0.40/month per replica but adds cross-region API latency (~50-150ms).
Break-Glass Emergency Access
Emergency access procedures are critical for incident response. Here's how to implement them securely.
Break-Glass Role Architecture
Monitoring Break-Glass Access
Emergency Access Procedure
Activation:
- Security team retrieves break-glass password from physical safe
- Second person retrieves YubiKey from separate secure location
- Both must be present (two-person rule)
Access:
Post-Incident:
- Revoke temporary credentials immediately
- Rotate all accessed secrets within 4 hours
- Document all actions taken in incident report
- Review CloudTrail logs for complete audit trail
- Conduct post-mortem on why break-glass was needed
Audit Logging with CloudTrail
Comprehensive audit logging is essential for security and compliance.
CloudTrail Configuration
Warning: Important: CloudTrail only logs management events by default. Data events (including
GetSecretValue) must be explicitly enabled.Note: ~0.01/month.
Athena Queries for Analysis
Cost Analysis & Optimization
Understanding the cost structure helps you optimize spending without compromising security.
Detailed Cost Scenarios
Scenario 1: 10 Static API Keys (No Rotation)
- Parameter Store Standard: $0/month (free tier)
- Secrets Manager: $4.00/month
- Recommendation: Parameter Store Standard
- Savings: $4.00/month
Scenario 2: 5 RDS Passwords (Monthly Rotation)
- Parameter Store: $0.25/month + manual rotation labor + downtime risk
- Secrets Manager: 0 rotation = $2.00/month
- Recommendation: Secrets Manager
- ROI: Automation worth the cost
Scenario 3: Lambda with High Traffic
- Without Extension: 1M invocations/month × 1 API call = $5.00/month
- With Extension: API calls reduced by 99% = $0.05/month
- Savings: $4.95/month (99% reduction)
Cost Optimization Strategies
Strategy 1: Hybrid Approach
Use Parameter Store for static configuration, Secrets Manager for rotating credentials:
Strategy 2: Consolidate Secrets
Instead of separate secrets for each credential component:
Strategy 3: Selective Replication
Only replicate critical production secrets:
Cost Analysis:
- 20 secrets, 2 replicas: $24/month
- 5 critical replicated + 15 primary only: $10/month
- Savings: $14/month (58% reduction)
Common Pitfalls & Solutions
Here are the technical issues I've encountered and how to solve them.
Pitfall 1: Default KMS Key for Cross-Account Access
Problem: Cross-account sharing fails with "AccessDeniedException" when using default aws/secretsmanager key.
Root Cause: AWS-managed keys cannot have their policy modified for cross-account access.
Solution: Always create customer-managed KMS keys:
Pitfall 2: Lambda VPC Configuration for Rotation
Problem: Rotation Lambda times out connecting to RDS in VPC.
Root Cause: Lambda not configured with VPC access.
Solution:
Pitfall 3: ECS Secrets Only Injected at Startup
Problem: After rotation, containers fail with authentication errors.
Root Cause: ECS injects secrets only at startup.
Solution: Implement graceful connection handling:
Pitfall 4: Excessive Lambda API Calls
Problem: Secrets Manager costs spike to $50+/month.
Root Cause: Fetching secret on every invocation without caching.
Solution: Use Lambda Extension (shown earlier in Pattern C).
Result: 99% cost reduction.
Pitfall 5: Missing CloudTrail Data Events
Problem: No audit trail for GetSecretValue operations.
Root Cause: Data events not enabled by default.
Solution: Enable data event logging (shown in Audit Logging section).
Pitfall 6: Storing Non-Secret Config in Secrets Manager
Problem: Paying $0.40/month for non-sensitive values.
Solution: Use decision framework:
Key Takeaways
Working with AWS secrets management has taught me these important lessons:
-
Service Selection is About Use Case: Reserve Secrets Manager for rotating credentials. Use Parameter Store for everything else. This simple rule can save 80% on costs.
-
Cross-Account Access Requires Customer-Managed Keys: The default
aws/secretsmanagerkey won't work. Create customer-managed KMS keys from day one to avoid migration pain. -
Container Injection is One-Time: Secrets injected at startup don't update on rotation. Design applications to handle connection refresh or use alternating-users strategy.
-
Lambda Extension Reduces Costs by 99%: For high-traffic Lambda functions, the extension's built-in caching is essential. It's a one-line addition that saves significant money.
-
CloudTrail Data Events are Critical: Enable them from day one. The cost is negligible (~$0.10 per 100,000 events) but the audit value is immeasurable.
-
Multi-Region Replication is a Business Decision: Don't replicate everything. Analyze RTO/RPO requirements and replicate only critical secrets. Cross-region API calls are often acceptable.
-
Break-Glass Procedures Need Testing: Untested emergency access is useless during incidents. Test quarterly to validate both technical and organizational readiness.
-
Automation Beats Process: Manual rotation costs 4/month. ROI is immediate.
The key is balancing security, cost, and operational complexity. Start simple with Parameter Store for static config, migrate sensitive credentials to Secrets Manager, implement rotation for databases, and add cross-region replication only where needed.
Related Topics: