Skip to content
Star
478
Star
478

Firebase Cloud Functions

This guide shows you how to work with Google Cloud Firebase Functions locally using the Firebase Emulator Suite. This lab demonstrates a synchronous HTTPS function that retrieves a secret from Secret Manager based on user name.

  1. Setup Environment:

    Open VS Code in the project folder and execute this command in the Command Palette:

    Terminal window
    > Dev Containers: Reopen in Container
  2. Start Firebase Emulators:

    Terminal window
    firebase emulators:start
  3. Run the Example:

    Terminal window
    python main.py
  1. Cloud Function:

    • Ensure: Stop the Firebase Emulator before attaching the debugger (it conflicts with the debugger port).
    • Run: Launch the Debug Cloud Function (Local) configuration from the Run and Debug tab.
    • Breakpoints: Set breakpoints inside get_secret in functions/main.py.
    • Send: Trigger a request via curl or the REST Client pointing to http://localhost:8080/.
  2. main.py:

    • Ensure: Stop the Firebase Emulator before attaching the debugger.
    • Run: Launch the Debug Cloud Function (Local) configuration.
    • Set: Set DEBUG_MODE=True in your .env.
    • Run: Open main.py and start the Python: Current File debugger.
  3. Tests:

    • Ensure: The Firebase Emulator must be running for individual test debugging.
    • Breakpoints: Set breakpoints in tests/test_get_secret.py.
    • Run: Open the Testing tab and click the Debug Test icon next to the desired test.
  • All tests: Run the automated script:
    Terminal window
    scripts/run_tests.sh
  • Individually: Use the VS Code Testing tab to run or debug specific test cases.

Open the Firebase Emulator UI and navigate to the Logs section to inspect function activity:

Terminal window
http://localhost:4000

Stop the emulators by pressing Ctrl+C in the terminal running firebase emulators:start. To remove volumes:

Terminal window
docker compose down -v