A secure, API-driven microservice for storing, retrieving, and rotating secrets in AWS Secrets Manager, built with FastAPI, Terraform, and AWS infrastructure.
Designed for internal teams to easily integrate secret management without directly handling credentials, improving security posture and reducing human error.
- Secure API Endpoints for retrieving and rotating secrets
- AWS Secrets Manager Integration for encrypted storage
- Automated Rotation via AWS EventBridge
- Infrastructure-as-Code with Terraform
- JWT Authentication for API requests
- Least Privilege IAM Policies
- CloudWatch Logging for audit and compliance
Flow:
- Client authenticates via JWT and calls
/get-secret/{name}or/rotate-secret/{name}. - API Gateway routes the request to a Lambda function (FastAPI app).
- Lambda uses IAM Role with least privilege to access AWS Secrets Manager.
- Secrets are retrieved or rotated, then returned securely to the client.
- EventBridge triggers periodic secret rotation to enforce key hygiene.
secrets-rotation-service/
βββ src/
β βββ main.py # FastAPI app entry point
β βββ secrets.py # AWS Secrets Manager functions
β βββ auth.py # JWT authentication
βββ infra/
β βββ main.tf # AWS provider, Lambda, Secrets Manager
β βββ iam.tf # IAM roles & policies
β βββ variables.tf # Config variables
βββ requirements.txt # Python dependencies
βββ README.md
βββ docs/
β βββ architecture.png # Architecture diagram
βΈ»
β Deployment
1οΈβ£ Provision AWS Resources
cd infra
terraform init
terraform apply
2οΈβ£ Deploy FastAPI to Lambda
Use AWS SAM, Zappa, or Docker-based Lambda packaging.
Example (Zappa):
pip install zappa
zappa init
zappa deploy dev
βΈ»
π Security Considerations
β’ No Secrets in Code: All secrets are stored in AWS Secrets Manager.
β’ Least Privilege: IAM roles only allow access to specific secrets.
β’ Encryption at Rest & In Transit: AWS KMS + HTTPS.
β’ JWT Auth: Ensures only authorized clients can call the API.
β’ Logging & Monitoring: CloudWatch for request tracing and auditing.
β’ Regular Rotation: Automated via EventBridge.
βΈ»
π§ͺ Example API Usage
Get Secret
curl -H "Authorization: Bearer <jwt_token>" \
https://<api_gateway_url>/get-secret/api_key
Response:
{
"secret": "some-secret-value"
}
Rotate Secret
curl -X POST -H "Authorization: Bearer <jwt_token>" \
https://<api_gateway_url>/rotate-secret/api_key
Response:
{
"status": "rotated",
"new_secret": "new-random-value"
}
βΈ»
π License
MIT License
---
