RousselTMLEARNING

TP · Google Cloud: from discovery to expertise

Lab: An API on the Functions Framework with the Firestore emulator

What you will learn in this TP
  • Use the Firestore emulator
  • Write a function with the Functions Framework
  • Prepare the container for Cloud Run

Introduction #

What you will learn in this section
  • Use the Firestore emulator
  • Write a function with the Functions Framework
  • Prepare the container for Cloud Run

Context. A product team wants a serverless user profile API. You build it entirely locally before any deployment.

Prerequisites: Docker, Python 3 and the Google Cloud SDK (gcloud with emulator components); no Google Cloud project or billing needed  ·  Estimated time: 50 min

An API that creates, reads and lists profiles in Firestore, run locally and in a container.

Hands-on #

Guided steps, with their solution.

  1. 1. Start the Firestore emulator

    Why? FIRESTORE_EMULATOR_HOST redirects the Python client.

    Start the emulator and install the libraries.
  2. 2. Write the function

    Why? The same code runs on Cloud Run functions unchanged.

    Create main.py: POST creates a profile, GET with ?id= reads it, GET without parameter lists profiles.
  3. 3. Run and test

    Why? functions-framework simulates the Google runtime.

    Run the function on port 8080, create a profile, read it back and list.
  4. 4. Containerise for Cloud Run

    Why? Cloud Run runs any container listening on $PORT.

    Write a Dockerfile, build the image and run it connected to the emulator.

Difficulty level : ●●●○○ (3/5)

My progress

  • ⏱ Estimated time : ≈ 50 min

Sign in to track your progress and take notes. Sign in

💬 Ask a question

Recommended Articles

Préparer la certification Google Associate Cloud Engineer

Guide de préparation à l'Associate Cloud Engineer : format, cinq domaines (mise en place, planifi...

Bonnes pratiques Google Cloud : organisation, sécurité, fiabilité et coûts

Les bonnes pratiques pour exploiter Google Cloud : organisation et dossiers, projets par environn...

Les logs avec OpenTelemetry : modèle de données, appenders, corrélation et collecte

Maîtriser le signal log : modèle de données LogRecord, Logs Bridge API et appenders (Logback, Log...

Kubernetes : exposer ses applications (Services, Ingress et Gateway API)

Exposer des applications dans Kubernetes : Services ClusterIP/NodePort/LoadBalancer, Ingress, Ing...

Stop moving to the Cloud, to micro-services...

I will certainly shock more than one person in this article, but don't hesitate to read to the en...

Identités et accès sur OVHcloud : compte, IAM, utilisateurs OpenStack et clés

Sécuriser l'accès à OVHcloud : double authentification du compte, IAM OVHcloud (identités, politi...

Cloud native : définition et principes d'une application cloud native

Qu'est-ce que le cloud native ? Définition de la CNCF, principes d'une application cloud native (...

Le calcul sur Azure : machines virtuelles, App Service, Functions et conteneurs

Choisir et utiliser le calcul Azure : machines virtuelles et groupes identiques (VMSS), App Servi...

Bonnes pratiques Cloud : sécurité, résilience, coûts et exploitation

Bonnes pratiques du Cloud Computing : piliers d'une architecture bien conçue, IAM et moindre priv...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!