Azure Functions: Serverless APIs with Triggers and Bindings
30-second answer
An Azure Function is a small piece of code that runs when its trigger fires: an HTTP request, a Service Bus message, an Event Grid event, a timer or a Cosmos DB change. Each function has exactly one trigger. Bindings connect inputs and outputs without client code, so an HTTP API can drop a message on a queue through an output binding. In the Python v2 programming model you write everything in function_app.py with decorators on func.FunctionApp(), such as @app.route, @app.service_bus_queue_trigger and @app.service_bus_queue_output.
Exam objective: 3.2.1 Build serverless APIs, including implementing triggers and bindings. (Skills measured as of October 7, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Open <strong>Function App</strong> and select <strong>+ Create</strong>.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Open Function App and select + Create.
- Choose the hosting option. Flex Consumption scales to zero, scales out fast and supports VNet integration.
- Pick the runtime stack, version and instance size (memory per instance).
- On Authentication, choose Managed identity so the app reaches its storage and Application Insights without keys.
- Review and Create. It also creates a storage account and Application Insights.
- On the Functions tab select + Create.
- Pick HTTP trigger. Authorization level Function means callers need a function key.
- The trigger is the @app.route decorator. Select Test/Run and send a body.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Functions: triggers and bindings
An Azure Function runs when its trigger fires: HTTP, Service Bus, Event Grid, timer, Cosmos DB and more. Bindings connect inputs and outputs without client code: an HTTP-triggered API can write a message to a queue with an output binding.
🤔 What happens if…
Read this tour as text
- Don’t make users wait. Summarising a 40-page PDF takes a minute. If the web API does it inline, requests pile up and time out. Put a message on a queue instead, reply "accepted", and let a worker do the slow part.
- Service Bus queue: peek-lock. An Azure Service Bus queue hands each message to one receiver. In peek-lock mode the message is locked, not removed. The worker completes it when done, or abandons it so it can be tried again. If the worker crashes, the lock expires and the message comes back.
- Dead-letter queue. A poison message fails every time. After max delivery count attempts (10 by default) Service Bus moves it to the dead-letter queue (DLQ), a sub-queue you read, fix and resubmit. Expired messages can go there too.
- Topics and subscriptions. A topic is a queue with many readers. Each subscription gets its own copy of every message, and filters (SQL or correlation) decide which messages a subscription keeps. One "document uploaded" message can feed indexing, billing and audit.
- Event Grid: something happened. Azure Event Grid pushes events (small facts: "blob created") to handlers. You can publish custom events to a custom topic. Event subscriptions pick the handler, and filters (event type, subject begins/ends with, advanced) cut out the noise.
- Event Grid retries. If the handler is down, Event Grid retries with exponential backoff, by default up to 30 attempts within 24 hours (you can lower both). After that it drops the event, unless you configured dead-lettering to a storage container.
- Functions: triggers and bindings. An Azure Function runs when its trigger fires: HTTP, Service Bus, Event Grid, timer, Cosmos DB and more. Bindings connect inputs and outputs without client code: an HTTP-triggered API can write a message to a queue with an output binding.
- Functions scale with the work. On the Flex Consumption plan a function app adds instances as messages arrive and scales to zero when idle. Premium keeps warm instances to avoid cold starts. Settings live in app settings, and you deploy a zip package or a container.
Build an order intake API with no server and almost no code: an HTTP-triggered function whose output binding drops each order on a Service Bus queue, connected with a managed identity instead of a connection string.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
A tiny API needs a whole web server just to queue a job.
😊 THE SOLUTION
An HTTP-triggered function with a Service Bus output binding.
- Boilerplate client code✓ Bindings
- Server idle all night✓ Pay per execution
- React to messages✓ Service Bus trigger
Start with a question
Do you really need a whole server just to run 20 lines of code when a file arrives?
Think of the motion-sensor light in a corridor. It doesn’t burn all night. Someone walks in, it switches on, does its job, and switches off. You pay for the minutes it was on.
Azure Functions works like that light. You write a small function, say which event switches it on (the trigger), and Azure runs it only when that happens. Bindings are the wiring to other services, so your function can write to a queue or read a blob without you writing connection code.
Explain it like I’m 10
Visual: triggers and bindings in motion
Watch an HTTP request wake a function, a binding drop a message on a queue, and the app scale out and back to zero.
Read the video script
- Nothing runs until a trigger firesA function sits idle until its trigger fires. That can be an HTTP request, a Service Bus message, a timer, an Event Grid event or a change in Cosmos DB.
- One trigger per functionEach function gets exactly one trigger. In the Python v2 model, the decorator says which. Here it's at app dot route, so an HTTP request wakes it up.
- An input binding reads dataNeed a file too? Add an input binding, like blob input. The blob arrives as a parameter before your code starts, so you don't write any Storage client code.
- Output binding sends the messageNow the output binding. Declare the queue in a decorator, take a func dot Out parameter, and call set. The Functions host drops the message on the queue for you. No Service Bus client code at all.
- Reply 202 straight awayThen it returns 202 Accepted right away. The slow model call happens later, in a worker that the queue triggers, so the caller isn't left waiting on an open connection.
- More work, more instancesWhen a rush of requests comes in, Azure adds more instances to keep up. In this example it goes from one to eight. You don't pick servers or set up a load balancer.
- No work? Back to zeroAnd when it goes quiet, the Flex Consumption plan scales back in, all the way to zero instances, unless you've asked for some to stay ready. Like a corridor light, it's only on when someone walks in.
The technical explanation
A function app is the unit you deploy and scale. Inside it you write one or more functions. Each function has:
- exactly one trigger, which starts it and usually passes in the data (the request, the message, the event);
- zero or more input bindings, which read extra data (a blob, a Cosmos DB item);
- zero or more output bindings, which write results (a queue message, a blob, a Cosmos DB document).
The Python v2 programming model
In the v2 model there’s no function.json. You create one FunctionApp object in function_app.py and decorate plain Python functions:
import json, logging
import azure.functions as func
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
# 1. HTTP API that queues work through an output binding
@app.route(route="summarise", methods=["POST"])
@app.service_bus_queue_output(arg_name="job", queue_name="summarise-jobs",
connection="ServiceBusConnection")
def summarise(req: func.HttpRequest, job: func.Out[str]) -> func.HttpResponse:
body = req.get_json()
job.set(json.dumps({"docId": body["docId"], "blob": body["blob"]}))
return func.HttpResponse(json.dumps({"status": "accepted"}), status_code=202,
mimetype="application/json")
# 2. Worker triggered by each queue message
@app.service_bus_queue_trigger(arg_name="msg", queue_name="summarise-jobs",
connection="ServiceBusConnection")
def worker(msg: func.ServiceBusMessage):
job = json.loads(msg.get_body().decode("utf-8"))
logging.info("Summarising %s (delivery %s)", job["docId"], msg.delivery_count)
summarise_document(job["blob"]) # raise to retry, return to complete
connection="ServiceBusConnection" is the name of an app setting, not the secret itself. In Azure that setting can be a connection string, or you can use identity-based connections (covered in the deploy lesson).
Common triggers and bindings
| Decorator | Fires when / does | Notes |
|---|---|---|
@app.route | An HTTP request arrives at /api/<route> | Returns func.HttpResponse. Auth levels below. |
@app.service_bus_queue_trigger / @app.service_bus_topic_trigger | A message arrives on a queue or subscription | Peek-lock: completed on success, abandoned on exception. |
@app.event_grid_trigger | Event Grid pushes an event | Receives func.EventGridEvent. The validation handshake is handled for you. |
@app.timer_trigger | A schedule is due | Six-field NCRONTAB, seconds first: 0 */15 * * * *. |
@app.cosmos_db_trigger | Items are inserted or updated in a container | Reads the change feed and needs a lease container. |
@app.blob_trigger | A blob is added or updated | For high volume, Event Grid-based blob triggers are faster. |
@app.service_bus_queue_output / @app.queue_output | Writes a message to Service Bus / Storage queue | Parameter type func.Out[str], then .set(). |
@app.blob_input, @app.cosmos_db_input | Reads a blob or item before the function runs | Value arrives as a parameter. |
Two more you’ll see often:
@app.event_grid_trigger(arg_name="event")
def on_blob(event: func.EventGridEvent):
data = event.get_json()
logging.info("%s on %s", event.event_type, event.subject)
@app.timer_trigger(schedule="0 0 2 * * *", arg_name="timer", run_on_startup=False)
def nightly_reindex(timer: func.TimerRequest):
if timer.past_due:
logging.warning("Running late")
rebuild_index()
You can split a big app into files with func.Blueprint() and register it with app.register_functions(bp).
HTTP authorization levels
| Level | Caller needs |
|---|---|
ANONYMOUS | Nothing. Anyone with the URL can call it. |
FUNCTION | A function key or host key, in the x-functions-key header or ?code= query string. This is the default. |
ADMIN | The master key. Keep it for admin tools only. |
Keys aren’t checked when you run locally with Core Tools. Keys prove “this caller has the key”, not who the user is. For user identity, add built-in authentication with Microsoft Entra ID or put Azure API Management in front.
-
1 Call
A client POSTs to /api/summarise with a function key.
-
2 Bind out
The output binding writes a message to summarise-jobs. The API returns 202.
-
3 Trigger
The Service Bus trigger hands the message to the worker function.
-
4 Settle
Success completes the message. An exception abandons it for another try.
Architect level Retries, timeouts and long AI work
A Service Bus-triggered function gets Service Bus’s own retry: abandon on failure, dead-letter after max delivery count. Event Grid has its own retry policy too. For other triggers you can add a function-level retry policy (fixed delay or exponential backoff) in some cases, but don’t stack retries on top of the broker’s retries without thinking about the total.
HTTP functions behind the Azure load balancer must respond within about 230 seconds, whatever the function timeout. That’s why the pattern above returns 202 straight away and lets a queue-triggered function do the slow model call. For multi-step workflows with waits and fan-out, Durable Functions (orchestrator and activity functions) keeps state for you.
Real-world business scenario
Wide World Importers (fictional)
- The problem
- Product descriptions for 40,000 items needed regenerating with a language model whenever a supplier sent new specs, and an old VM script ran all day even when nothing changed.
- What they used
- A Python v2 function app with an Event Grid trigger on the specs container, a Service Bus output binding that queues one job per product, a Service Bus-triggered worker that calls the model and a Cosmos DB output binding that saves the new description. A nightly timer trigger re-queues anything that failed.
- Why that choice
- Each step runs only when there's work, bindings removed most of the SDK code, and failed products end up in the dead-letter queue instead of vanishing.
- The result
- The VM was switched off, new specs show up on the site within minutes, and the team edits one function_app.py file instead of three scripts.
When to use it and when not to
✓ Use it when…
- Small units of code that should run in response to HTTP calls, messages, events or schedules.
- Glue between services where bindings remove most of the client code.
- Spiky workloads that sit idle a lot and should scale to zero.
✕ Think twice when…
- Long-running processes or servers that need to stay up and hold connections. Use Container Apps or App Service.
- A big web app with many routes and its own framework. App Service or Container Apps fits better.
- Work that must answer an HTTP caller after several minutes. Queue it and reply 202 instead.
↔ Alternatives to consider
- Azure Container Apps for containerised APIs and workers with KEDA scaling.
- Durable Functions for stateful, multi-step workflows.
- Azure Logic Apps for low-code workflows with connectors.
Test yourself with exercises
5 original practice questions in the AI-200 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What's the difference between a trigger and a binding?
Model answer
The trigger is why the function runs: an HTTP call, a message, a timer. A function has exactly one. Bindings are optional extra connections for data in or out, like writing to a queue or reading a blob, and a function can have several. The trigger is itself a kind of input binding.
Intermediate How do you write a Service Bus message from an HTTP function in Python without the Service Bus SDK?
Model answer
I add @app.service_bus_queue_output with arg_name, queue_name and connection, then add a parameter of type func.Out[str] with that name. Inside the function I call msg.set(json_text). The Functions host sends it to the queue when the function finishes.
Experienced developer What happens to a Service Bus message if your queue-triggered function throws an exception?
Model answer
The trigger uses peek-lock. If the function succeeds, the host completes the message. If it throws, the host abandons it, so it's delivered again. After the queue's max delivery count, 10 by default, Service Bus dead-letters it. So my function should be idempotent and only throw for errors worth retrying.
Scenario You need a public endpoint for a partner to request summaries, but only partners with a key should get in. How would you set up the function?
Model answer
An HTTP trigger with auth_level FUNCTION, so callers pass a function key in the x-functions-key header or the code query string. I'd give the partner their own key so I can revoke it alone. For real user identity I'd add App Service authentication with Microsoft Entra ID or put API Management in front.
Quick revision
Key points
- One trigger per function. Bindings (input and output) are optional and can be many.
- Python v2 - function_app.py, app = func.FunctionApp(), decorators per function. No function.json.
- HTTP - @app.route with auth levels ANONYMOUS, FUNCTION, ADMIN.
- Service Bus trigger completes on success and abandons on exception. Output bindings use func.Out[...] and .set().
- The connection argument names an app setting, not the connection string itself.
Important terminology
- Trigger
- What starts a function run, such as an HTTP request or a queue message. Every function has exactly one.
- Binding
- A declared connection to another service that passes data in (input) or out (output) without writing SDK code.
- Python v2 programming model
- The decorator-based way to write Python functions in function_app.py, with no function.json files.
- func.FunctionApp
- The object in function_app.py that functions are registered on with decorators.
- Authorization level
- Whether an HTTP function needs a key - ANONYMOUS (none), FUNCTION (a function or host key) or ADMIN (the master key).
- Connection setting
- The name of an app setting that tells a trigger or binding how to reach a service, by connection string or by identity.
- NCRONTAB
- The six-field schedule format used by the timer trigger, with seconds first, such as 0 */5 * * * *.
Common mistakes
- Putting the connection string straight into the decorator instead of an app setting name.
- Expecting a Service Bus-triggered function to retry forever. After max delivery count the message is dead-lettered.
- Writing six-field NCRONTAB as five-field cron.
Exam tips
- "Start when a message lands in a queue" = Service Bus queue trigger.
- "Write to a queue without SDK code" = output binding.
- "Run every 15 minutes" = timer trigger, 0 */15 * * * *.
Five quick revision questions
-
1.How many triggers can a function have?Show
Exactly one.
-
2.Which file holds Python v2 functions?Show
function_app.py.
-
3.Which decorator defines an HTTP-triggered function?Show
@app.route.
-
4.Which auth level needs no key?Show
ANONYMOUS.
-
5.How do you set an output binding value in Python?Show
Call .set() on the func.Out parameter.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Configure and Deploy Function Apps
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.