Setup
Install AWS CLI
Ensure you have AWS credentials configured:Configure AWS Credentials
Template Functions
awsSecretsManager
Retrieve structured JSON secrets:
awsSecretsManagerRaw
Retrieve raw secret strings:
Configuration
Configure AWS Secrets Manager in chezmoi:~/.config/chezmoi/chezmoi.toml
- Standard AWS environment variables (
AWS_PROFILE,AWS_REGION) - AWS config files (
~/.aws/config,~/.aws/credentials)
Usage Examples
Database Credentials (JSON)
Store a JSON secret in AWS:~/.config/db/config.yml.tmpl
API Tokens (Raw)
Multiple API Keys
~/.config/api-keys.env.tmpl
AWS Credentials for Different Accounts
Store credentials for other AWS accounts:~/.aws/credentials.tmpl
SSH Private Keys
Application Configuration
~/.config/app/config.yml.tmpl
Using Different Regions and Profiles
Per-Profile Configuration
Using ARNs
You can use full ARNs for cross-region or cross-account access:Advanced Usage
Versioned Secrets
AWS Secrets Manager supports versioning. By default, chezmoi retrieves the current version (AWSCURRENT).Binary Secrets
For binary secrets,awsSecretsManagerRaw automatically decodes base64 data.
Nested JSON
Access nested JSON structures:Conditional Secrets by Environment
~/.config/app/config.yml.tmpl
Complete Examples
Multi-Service Configuration
~/.config/services.yml.tmpl
Kubernetes Secrets
~/.kube/config.tmpl
IAM Permissions
Your AWS user/role needs these permissions:Troubleshooting
AccessDeniedException
Ensure your IAM user/role hassecretsmanager:GetSecretValue permission:
ResourceNotFoundException
Verify the secret exists in the correct region:Invalid JSON
If usingawsSecretsManager (not awsSecretsManagerRaw), ensure your secret is valid JSON:
Credentials Not Found
Verify AWS credentials are configured:Testing Templates
Test template functions:Best Practices
- Use IAM roles: On EC2/ECS, use IAM roles instead of access keys
- Least privilege: Grant only necessary permissions to specific secrets
- Use encryption: Enable encryption at rest for secrets
- Rotate secrets: Enable automatic rotation for database credentials
- Use resource policies: Control access with resource-based policies
- Tag secrets: Use tags for organization and cost allocation
- Monitor access: Enable CloudTrail logging for secret access
- Use VPC endpoints: Access Secrets Manager privately from VPC
Cost Considerations
AWS Secrets Manager pricing:- $0.40 per secret per month
- $0.05 per 10,000 API calls
- Caching reduces API calls
- Use AWS Systems Manager Parameter Store for simpler secrets (cheaper)
- Delete unused secrets