A FastAPI Cookiecutter template that instantly scaffolds an async API and automatically provisions production-ready AWS ECS Fargate & RDS infrastructure via
deploy-stack.
Scaffolding an async FastAPI application is quick, but deploying it to AWS securely with private subnets, load balancing, health checks, and secrets management takes hours.
This template uses a post-generation hook. The moment you generate your project, it silently passes your configuration to deploy-stack to provision a zero-CVE Dockerfile, AWS Fargate Terraform modules, and keyless GitHub Actions deployment pipelines.
You do not need to clone this repository. Simply install Cookiecutter globally:
pip install cookiecutter(Note: You do not need to pre-install deploy-stack. The template automatically executes the latest CLI version via npx.)
Run Cookiecutter directly against this GitHub repository:
cookiecutter gh:anton-codes-iac/cookiecutter-fastapi-deploy-stackYou will be prompted for:
project_name: The name of your application.python_version: Python version (3.12, 3.11, or 3.10).aws_region: Target AWS region for deployment.include_managed_rds: Selectyto provision an Amazon RDS PostgreSQL database.port: Port for Uvicorn (default: 8000).
- Scaffold: Cookiecutter generates an async FastAPI application structure with Pydantic settings and database bindings.
- Generate: The post-generation hook intercepts project creation and runs
deploy-stackin headless mode, generatingterraform/,.github/, and an Alpine Dockerfile with 0 CVEs. - Provision (Day 1): Navigate into your new directory and run
npx --yes deploy-stack apply. - Automate (Day 2): Push your code to GitHub. The generated CI/CD pipeline deploys subsequent updates using AWS IAM OIDC (no long-lived access keys).
Running npx deploy-stack apply provisions:
- Amazon ECS (Fargate): Serverless container compute running Uvicorn behind an unprivileged user.
- Amazon RDS (PostgreSQL): (Optional) Managed relational database in a private subnet with automated password rotation.
- Application Load Balancer (ALB): Routes public traffic and verifies
/healthendpoints. - AWS Secrets Manager: Secure storage for your application environment variables.
- Amazon ECR: Private container registry with automated vulnerability scanning.
To remove all provisioned infrastructure, destroy the database, and stop billing, run:
npx --yes deploy-stack destroyThis template is a headless automation wrapper around the core deploy-stack CLI.
For custom architectures, full CLI flags, or supporting other web frameworks, visit the main deploy-stack repository.
This tool provisions real AWS resources which will incur charges on your AWS bill. An ECS Fargate cluster with an Application Load Balancer running 24/7 typically costs around ~$25 - $35/month minimum depending on region. A managed RDS database will add additional monthly costs.
Disclaimer: The maintainers are not responsible for any unexpected AWS charges, security breaches, or data loss. Please monitor your AWS Billing Dashboard.
MIT