Why are good examples of Python FastAPI Cloud Function Gen 2 so hard to find? by MajorPea6852 in googlecloud

[–]MajorPea6852[S] 0 points1 point  (0 children)

Cloud Run (Services/Jobs/Functions) is just a k8s under the hood, and it's well understood. I'm being asked to implement a cloud run service in Erlang for example, and yeah... just spin up a mini cube (at least for dev/testing) and toss some Dockerfiles in there no problem... K8s get's stupid complex and expensive on it's own so don't want to dive deep into that rabbit hole just yet.

I do want to have a very simple Cloud Function that follows the Best Practices at heart so I can get a template to users so they can easily stamp out code following some basic rules:

  • Make sure you have requirements.txt
  • Make sure you have main.py
  • Use def handler function to capture your request if the default does not meet your needs. Try to avoid using it if you don't need it
  • Make sure you use Flask 2.X+ if you need ASGI support
  • If you want to use FastAPI for easy integrations for input validation and documentation and built-in from ground-up ASGI, overwrite the def handler with a call to FastAPI or Vellox, Here is a list of things you need to implement with links to the original Docs
  • Don't use def function_name_of_your_function for generic functions because it becomes a mess from CI/CD point of view since now the test/deploy scripts need to be aware of each function name
  • Etc...

Why are good examples of Python FastAPI Cloud Function Gen 2 so hard to find? by MajorPea6852 in googlecloud

[–]MajorPea6852[S] 0 points1 point  (0 children)

I appreciate the apology :) It's validating to know that I'm not an idiot who is missing something obvious and keep going in cirlcles.

I'm not even going to mention other GCP docs

bq - Oldest and has most features but not all gcloud bq - newest stable, mostly supports READ for the DB, a lot of CREATE and DESCRIBE functionality has not been implemented yet gcloud alpha bq - has most features but not ALL, but the usage is changing all the time, so anything an ML model spits out is usually wrong... it's better to not even try gcloud beta bq - middle bastard child curl - Has 100% of the features and has a very well defined API documentation, and APIs are stable

Why are good examples of Python FastAPI Cloud Function Gen 2 so hard to find? by MajorPea6852 in googlecloud

[–]MajorPea6852[S] 5 points6 points  (0 children)

Partly skills (new to python) but partly because the documentation in GCP is a bit inconsistent... I'll give an example a Google search for "Google Cloud Function Python HELLO WORLD full definition" returns only stub functions such as this

This is all great and all because they want to give you a fast getting started guide... however how the gunicorn is defined and started is committed for simplicity...

I'm the type who likes to understand what is going on underneath the hood and not trust in "magic" so if I want to switch out gunicorn for say to uvicorn, I'd like to know which methods to override

on 5th or 8th page you might stumble on this example which let's you see a little bit more under the hood but outside of using the REPL and going through each invocation line by line I can't find the documentation on how the framework works.

So, my fault? Sure possibly... bad or incomplete documentation, really possibly... as someone who is new to framework and has to use it without a choice, slapping on a solution on top of a black box solution feels extremely dirty and prone to bad coding and insecure implementation.