Skip to content

Deploy production grade application to AWS and GCP in minutes.

License

Notifications You must be signed in to change notification settings

TitasKe/launchflow

Β 
Β 

Repository files navigation

Deploy to AWS / GCP with Python

πŸ“– Docs Β  | Β  ⚑ Quickstart Β  | Β  πŸ‘‹ Slack

LaunchFlow is an open source Python SDK that lets you launch websites, APIs, and workers to AWS / GCP with minimal configuration.

  • Serverless Deployments
  • Auto-Scaling VMs
  • Kubernetes Clusters (in preview)
  • Static Sites (in preview)
  • Terraform Resources
  • Pulumi Resources (coming soon)
  • Custom Resources (coming soon)

Use the Python SDK to define your infrastructure in code, then run lf deploy to deploy everything to a dedicated VPC environment in your cloud account.

Fully customizable but configured by default - no messy YAML required.

🧠 Concepts

Services - Docs

Services allow you to deploy websites, APIs, background workers and other types of applications to your cloud account with minimal setup.

Note

LaunchFlow is not just for deploying Python apps. The Python SDK is used to define your infrastructure in code, but you can deploy any application that runs on a VM, container, or serverless environment.

Python is just the language for your cloud configuration, similar to how Terraform uses HCL.

Click the dropdown below to see the service types that are currently supported.

Services Types
  • Static Websites
    • (AWS) S3 Static Site - coming soon
    • (GCP) GCS Static Site with Load Balancer - coming soon
    • (GCP) Firebase Static Site - coming soon
  • Serverless APIs
    • (AWS) Lambda Service - coming soon
    • (GCP) Cloud Run Service - Docs
  • Auto-Scaling VMs
    • (AWS) ECS Fargate Service - Docs
    • (GCP) Compute Engine Service - Docs
  • Kubernetes Clusters
    • (AWS) EKS - coming soon
    • (GCP) GKE - Docs

Resources - Docs

Resources are the cloud services that your application uses, such as databases, storage, queues, and secrets. LaunchFlow provides a simple way to define, manage, and use these resources in your application.

Click the dropdown below to see the resource types that are currently supported.

Resource Types
  • Cloud Storage
    • (AWS) S3 Bucket - Docs
    • (GCP) GCS Bucket - Docs
  • Postgres
    • (AWS) RDS Postgres - Docs
    • (GCP) Cloud SQL Postgres - Docs
  • Redis
    • (AWS) ElastiCache Redis - Docs
    • (GCP) Memorystore Redis - Docs
  • Task Queues
    • (AWS) SQS Queue - Docs
    • (GCP) Pub/Sub - Docs
    • (GCP) Cloud Tasks - Docs
  • Secrets
    • (AWS) Secrets Manager - Docs
    • (GCP) Secret Manager - Docs
  • Custom Domains
    • (AWS) Route 53 - Docs
    • (GCP) Custom Domain Mapping - Docs
  • Monitoring & Alerts
    • (AWS) CloudWatch - coming soon
    • (GCP) StackDriver - coming soon
  • Custom Terraform Resources - coming soon
  • Custom Pulumi Resources - coming soon

Environments - Docs

Environments group Services and Resources inside a private network (VPC) on either GCP or AWS. You can create multiple environments for different stages of your workflow (e.g. development, staging, production) and switch between them with a single command.

βš™οΈ Installation

pip install launchflow

πŸš€ Quickstart

Deploy FastAPI to ECS Fargate on AWS:

Step 1. Create a new Python file (e.g. main.py) and add the following code:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def index():
    return f'Hello from {lf.environment}!'

Step 2. Add a Service type to your Python file:

from fastapi import FastAPI
import launchflow as lf

app = FastAPI()

@app.get("/")
def index():
    return f'Hello from {lf.environment}!'

# Deploy this FastAPI app to ECS Fargate on AWS
api = lf.aws.ECSFargate("my-api")

Step 3. Run the lf deploy command to deploy your infrastructure:

lf deploy

This command will do the following:

  1. Generate a Dockerfile and launchflow.yaml file (if you don't have one)
  2. Create a new VPC (Environment) in your AWS account (if you don't have one)
  3. Create a new ECS Fargate service and task definition (if you don't have one)
  4. Create a new Application Load Balancer and Route 53 DNS record (if you don't have one)
  5. Build a Docker image and push it to ECR
  6. Deploy your FastAPI app to the new ECS Fargate service
  7. Output the URL & DNS settings of your new FastAPI app

Step 4. Add a Resource type and customize the Service:

from fastapi import FastAPI
import launchflow as lf

# Resource permissions are automatically configured for you
bucket = lf.gcp.S3Bucket("my-bucket")

app = FastAPI()

@app.get("/")
def index():
    bucket.upload_from_string(f"Hello from {lf.environment}!", "hello.txt")
    return bucket.download_file("hello.txt").decode()

# You can customize the Fargate service with Python
api = lf.aws.ECSFargate("my-api", domain="your-domain.com", memory=512, cpu=256)

Step 5. Run the lf deploy command to deploy your updated infrastructure:

lf deploy

πŸ“– Examples

Click the dropdowns below to see the example's code.

Deploy FastAPI to ECS Fargate (AWS)
from fastapi import FastAPI
import launchflow as lf

app = FastAPI()

@app.get("/")
def index():
    return f'Hello from {lf.environment}!'

# Deploy this FastAPI app to ECS Fargate on AWS
api = lf.aws.ECSFargate("my-api", domain="your-domain.com")
Deploy FastAPI to Cloud Run (GCP)
from fastapi import FastAPI
import launchflow as lf

app = FastAPI()

@app.get("/")
def index():
    return f'Hello from {lf.environment}!'

# Deploy Postgres hosted on (GCP) Cloud SQL 
api = lf.gcp.CloudRun("my-api", domain="your-domain.com")
Deploy Postgres to RDS & EC2 (AWS)
import launchflow as lf

# Create / Connect to a Postgres Cluster on CloudSQL
postgres = lf.aws.RDSPostgres("postgres-cluster", disk_size_gb=10)

# Or on a Compute Engine VM
postgres = lf.aws.ComputeEnginePostgres("postgres-vm")

if __name__ == "__main__":
    # Built-in utility methods for using Postgres
    postgres.query("SELECT * FROM my_table")

    # Built-in connectors for Python ORMs
    postgres.sqlalchemy_engine()
    postgres.django_settings()
Deploy Postgres to Cloud SQL & Compute Engine (GCP)
import launchflow as lf

# Create / Connect to a Postgres Cluster on CloudSQL
postgres = lf.gcp.CloudSQLPostgres("postgres-cluster", disk_size_gb=10)

# Or on a Compute Engine VM
postgres = lf.gcp.ComputeEnginePostgres("postgres-vm")

if __name__ == "__main__":
    # Built-in utility methods for using Postgres
    postgres.query("SELECT * FROM my_table")

    # Built-in connectors for Python ORMs
    postgres.sqlalchemy_engine()
    postgres.django_settings()

πŸ‘€ Coming Soon

Deploy a static React app to a CDN (GCP)

[!IMPORTANT]
This example is not yet available in the LaunchFlow Python SDK.

import launchflow as lf

# Deploy a static React app to a GCS Bucket with a CDN
bucket = lf.gcp.BackendBucket(
    "react-app", "./dst" domain=f"{lf.environment}.app.launchflow.com"
)

if __name__ == "__main__":
   # Use Python to easily automate non-Python applications
  print(f"Bucket URL: {bucket.url}")
Full on scripting with Python (GCP)

[!IMPORTANT]
This example is not yet available in the LaunchFlow Python SDK.

import launchflow as lf


backend = lf.gcp.CloudRun(
    "fastapi-api", domain=f"{lf.environment}.api.launchflow.com"
)

frontend = lf.gcp.BackendBucket(
    "react-static-app",
    static_directory="./dst",
    domain=f"{lf.environment}.console.launchflow.com",
    env={
        "LAUNCHFLOW_API_URL": backend.url
    }
)

result = lf.deploy(backend, frontend, environment="dev")

if not result.successful:
    print(result.error)
    exit(1)

print(f"Frontend URL: {frontend.url}")
print(f"Backend URL: {backend.url}")

Don't see what you're looking for?

Reach out to [email protected] to speed up development of the feature you need. Most of the unfinished features are already in development and can be completed in under a week - we just need to know what to prioritize!

About

Deploy production grade application to AWS and GCP in minutes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 89.7%
  • HCL 7.6%
  • Jinja 1.9%
  • Other 0.8%