- Google Cloud SDK installed (
gcloud) - GCP project with billing enabled
-
Copy and configure
.envfile:cp .env.example .env
-
Edit
.envwith your settings:GCP_PROJECT_ID=your-project-id GCP_REGION=us-central1 GCF_FUNCTION_NAME=flask-app GCF_ALLOW_UNAUTHENTICATED=true
Linux/Mac:
./deploy-gcf.shWindows:
deploy-gcf.batThat's it! The script will deploy your app to Cloud Functions.
- Loads configuration from
.env - Sets your GCP project
- Deploys to Cloud Functions Gen 2 with Python 3.11
- Uses
main.pyas entry point - Outputs the function URL
- Uses
main.pyas entry point (imports Flask app fromapp.py) - Supports multiple endpoints in a single deployment
- Cold starts may occur for infrequent requests
If you prefer manual control:
gcloud functions deploy flask-app \
--gen2 \
--runtime python311 \
--trigger-http \
--allow-unauthenticated \
--entry-point main \
--region us-central1 \
--source .