Skip to content
Star
478
Star
478

Functions

This guide shows you how to work with Azure Functions using Python and Azure Functions Core Tools. This lab demonstrates how to develop, run, debug, test, and validate an HTTP-triggered function locally.

  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 Function Host:

    Terminal window
    func start
  3. Run the Example:

    Terminal window
    python main.py
  1. function_app.py:

    • Open: Open function_app.py.
    • Breakpoints: Set breakpoints inside get_secret.
    • Run: From the Run and Debug tab, select Attach to Python Functions and press F5.
  2. main.py:

    • Open: Open main.py.
    • Breakpoints: Set breakpoints in the main function.
    • Run: Press F5 to start debugging.
  3. Tests:

    • Open: Open a test file (e.g., tests/test_functions.py).
    • Breakpoints: Set breakpoints in the test code.
    • Run: Use the VS Code Testing tab and click the Debug Test icon next to the test you want to debug.
  • Individually: Run tests individually from the VS Code Testing tab.
  • All tests: Run the automated script:
    Terminal window
    scripts/run_tests.sh
  • Run: Execute the main script and review its output:
    Terminal window
    python main.py
  • Verify: The user defined in ADMIN_USERNAME (.env) should receive a 200 response with the secret value. Any other user should receive 403.
Terminal window
docker compose down -v