A comprehensive project template for deploying a Python FastAPI application to AWS, Azure, or GCP using Pulumi infrastructure as code and GitHub Actions workflows.
.
βββ api/ # Python FastAPI application
β βββ main.py # API endpoints
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Container configuration
βββ infra/ # Infrastructure as Code (Pulumi)
β βββ aws/ # AWS infrastructure
β βββ azure/ # Azure infrastructure
β βββ gcp/ # GCP infrastructure
βββ k8s/ # Kubernetes manifests
β βββ deployment.yaml # K8s deployment config
β βββ service.yaml # K8s service config
βββ .github/
βββ workflows/ # GitHub Actions workflows
βββ deploy-aws.yml
βββ deploy-azure.yml
βββ deploy-gcp.yml
- REST API: Simple FastAPI application with
/and/healthendpoints - Multi-Cloud Support: Deploy to AWS, Azure, or GCP
- Multiple Deployment Options:
- AWS: Lambda, EC2, or EKS
- Azure: Functions, VM, or AKS
- GCP: Cloud Run, Compute Engine, or GKE
- Infrastructure as Code: Pulumi for consistent infrastructure management
- CI/CD: GitHub Actions workflows for automated deployment
- Containerized: Docker support for consistent deployments
-
Cloud Provider Account:
- AWS account with appropriate permissions
- Azure subscription
- GCP project
-
Tools:
- Pulumi CLI
- Docker
- kubectl (for Kubernetes deployments)
-
GitHub Secrets (configure in your repository):
For AWS:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
For Azure:
AZURE_CREDENTIALS(JSON format service principal)
For GCP:
GCP_CREDENTIALS(JSON format service account key)
For all providers:
PULUMI_ACCESS_TOKENPULUMI_CONFIG_PASSPHRASE
cd api
pip install -r requirements.txt
python main.pyVisit http://localhost:8080 to test the API.
cd api
docker build -t multi-cloud-api .
docker run -p 8080:8080 multi-cloud-api- Push your code to GitHub
- Go to Actions tab in your repository
- Select the appropriate workflow:
- Deploy to AWS
- Deploy to Azure
- Deploy to GCP
- Click Run workflow
- Choose your deployment type and provide required inputs
- Click Run workflow
cd infra/aws
pip install -r requirements.txt
# Initialize Pulumi stack
pulumi stack init dev
# Configure deployment
pulumi config set deploymentType lambda # or ec2, eks
pulumi config set appName multi-cloud-api
# Deploy
pulumi upcd infra/azure
pip install -r requirements.txt
# Initialize Pulumi stack
pulumi stack init dev
# Configure deployment
pulumi config set deploymentType functions # or vm, aks
pulumi config set appName multi-cloud-api
pulumi config set location eastus
# Login to Azure
az login
# Deploy
pulumi upcd infra/gcp
pip install -r requirements.txt
# Initialize Pulumi stack
pulumi stack init dev
# Configure deployment
pulumi config set deploymentType functions # or compute, gke
pulumi config set appName multi-cloud-api
pulumi config set gcpProject YOUR_PROJECT_ID
pulumi config set region us-central1
# Authenticate with GCP
gcloud auth application-default login
# Deploy
pulumi up-
Lambda (Serverless)
- Best for: Event-driven, low-traffic APIs
- Scales automatically
- Pay per request
-
EC2 (Virtual Machine)
- Best for: Consistent workloads
- Full control over environment
- Fixed pricing
-
EKS (Kubernetes)
- Best for: Complex applications with multiple services
- High availability and scalability
- Advanced orchestration
-
Functions (Serverless)
- Best for: Event-driven workloads
- Automatic scaling
- Pay per execution
-
VM (Virtual Machine)
- Best for: Traditional applications
- Full OS control
- Predictable pricing
-
AKS (Kubernetes)
- Best for: Containerized microservices
- Enterprise-grade orchestration
- High availability
-
Cloud Run (Serverless Containers)
- Best for: Containerized APIs
- Automatic scaling to zero
- Pay per use
-
Compute Engine (Virtual Machine)
- Best for: Custom configurations
- Persistent workloads
- Full machine control
-
GKE (Kubernetes)
- Best for: Cloud-native applications
- Multi-container deployments
- Advanced networking
For EKS, AKS, or GKE deployments, the workflows automatically apply Kubernetes manifests after cluster creation.
To manually deploy to an existing cluster:
# Update the image in deployment.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
# Get the service URL
kubectl get service multi-cloud-api-serviceOnce deployed, test your API:
# Replace <URL> with your deployment URL
curl https://<URL>/
# Response: {"hi": "Hello from Multi-Cloud API!"}
curl https://<URL>/health
# Response: {"status": "healthy"}- Lambda: CloudWatch Logs
- EC2: CloudWatch Logs (requires agent)
- EKS: CloudWatch Container Insights
- Functions: Application Insights
- VM: Azure Monitor
- AKS: Azure Monitor for containers
- Cloud Run: Cloud Logging
- Compute Engine: Cloud Logging (requires agent)
- GKE: Cloud Logging and Monitoring
- Lambda/Functions/Cloud Run: Best for intermittent traffic
- EC2/VM/Compute Engine: Use reserved instances for consistent workloads
- Kubernetes: Enable autoscaling and right-size your nodes
To destroy infrastructure:
cd infra/<cloud-provider>
pulumi destroy-
Secrets Management:
- Use GitHub Secrets for sensitive data
- Never commit credentials to version control
-
Network Security:
- Configure security groups/firewall rules
- Use HTTPS in production
-
IAM/RBAC:
- Follow principle of least privilege
- Use managed identities where possible
-
Container Security:
- Scan images for vulnerabilities
- Use minimal base images
- Keep dependencies updated
- Ensure
PULUMI_ACCESS_TOKENis set correctly - Check stack configuration with
pulumi config
- Verify Dockerfile syntax
- Check Docker daemon is running
- Review GitHub Actions logs
- Check cloud provider quotas
- Verify IAM permissions
Feel free to submit issues and enhancement requests!
MIT License - feel free to use this template for your projects.