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

Le calcul sur Google Cloud : Compute Engine, GKE, Cloud Run et Cloud Functions

Choisir le calcul sur Google Cloud : VM Compute Engine et groupes d'instances gérés, Google Kuber...

Les bases de données Google Cloud : Cloud SQL, AlloyDB, Spanner, Firestore et Bigtable

Choisir une base de données sur Google Cloud : Cloud SQL et AlloyDB pour le relationnel, Spanner ...

Le stockage Google Cloud : Cloud Storage, disques persistants et Filestore

Stocker des données sur Google Cloud : Cloud Storage (classes, emplacements régionaux, birégionau...

Informatique serverless : définition, FaaS et cas d'usage

L'informatique serverless expliquée : Function as a Service (FaaS), fonctionnement, avantages, li...

Exploiter Google Cloud : observabilité, sécurité, infrastructure as code et coûts

Exploiter Google Cloud : Cloud Monitoring, Cloud Logging et Cloud Trace (Google Cloud Observabili...

Comprendre Google Cloud : régions, projets, hiérarchie, outils et tarification

Les bases de Google Cloud : régions et zones, hiérarchie organisation, dossiers et projets, API à...

Le réseau Google Cloud : VPC mondial, sous-réseaux, pare-feu et équilibrage

Concevoir le réseau sur Google Cloud : VPC mondial et sous-réseaux régionaux, règles de pare-feu ...

IAM sur Google Cloud : rôles, comptes de service et règles d'administration

Gérer les accès sur Google Cloud : principaux, rôles de base, prédéfinis et personnalisés, liaiso...

Préparer la certification Google Cloud Digital Leader

Guide de préparation au Cloud Digital Leader : format, domaines (transformation numérique, donnée...

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!