Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cookiecutter-fastapi-deploy-stack ☁️🚀

A FastAPI Cookiecutter template that instantly scaffolds an async API and automatically provisions production-ready AWS ECS Fargate & RDS infrastructure via deploy-stack.

Cookiecutter FastAPI

Why?

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.

Installation

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.)

Usage

Run Cookiecutter directly against this GitHub repository:

cookiecutter gh:anton-codes-iac/cookiecutter-fastapi-deploy-stack

You will be prompted for:

  1. project_name: The name of your application.
  2. python_version: Python version (3.12, 3.11, or 3.10).
  3. aws_region: Target AWS region for deployment.
  4. include_managed_rds: Select y to provision an Amazon RDS PostgreSQL database.
  5. port: Port for Uvicorn (default: 8000).

How it Works

  1. Scaffold: Cookiecutter generates an async FastAPI application structure with Pydantic settings and database bindings.
  2. Generate: The post-generation hook intercepts project creation and runs deploy-stack in headless mode, generating terraform/, .github/, and an Alpine Dockerfile with 0 CVEs.
  3. Provision (Day 1): Navigate into your new directory and run npx --yes deploy-stack apply.
  4. 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).

🏗️ What gets provisioned?

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 /health endpoints.
  • AWS Secrets Manager: Secure storage for your application environment variables.
  • Amazon ECR: Private container registry with automated vulnerability scanning.

🗑️ Teardown (Stopping AWS Billing)

To remove all provisioned infrastructure, destroy the database, and stop billing, run:

npx --yes deploy-stack destroy

🧠 Powered by deploy-stack

This 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.

💰 AWS Costs & Disclaimer

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.

License

MIT

About

Cookiecutter template for FastAPI on AWS ECS Fargate & RDS via deploy-stack

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages