Getting Started with Azure Functions: Triggers, Bindings and Deployment
After hosting a full web app on App Service, I kept running into small jobs that didn’t deserve one: resize an image when it lands in storage, process a message from a queue, clean up old records every night.
That is what Azure Functions is for. You write the code for the task; Azure runs it when something happens. Two ideas make it so productive — triggers and bindings — and both show up in the walkthrough below, from a local project to a deployed function.
Triggers and bindings
The diagram at the top of this article shows how a function is built:
- A trigger starts the function. Every function has exactly one — an HTTP request, a timer, a new queue message, a new blob, and so on.
- Input bindings bring data into the function, for example a file from Blob Storage.
- Output bindings send data out, for example a message to a queue.
The nice part is that bindings replace a lot of SDK code. You don’t open connections or write retry loops — you declare the binding and use it like a normal variable.
Choose the hosting plan first
Before writing code, decide where the function will run, because it affects how long the function can run and how fast it starts:
| Plan | Scaling | Cold start | Max run time | Use it when |
|---|---|---|---|---|
| Consumption | Automatic, scales to zero | Yes | 5 min by default (10 max) | Low or spiky traffic, lowest cost |
| Premium | Pre-warmed instances | No | Unlimited | Latency matters, you need VNet access |
| Dedicated (App Service) | Manual or autoscale | No | Unlimited | You already pay for an App Service plan |
Watch the clock: The Consumption plan is cheap until a function needs more than the time limit. Long-running work should be split into smaller steps using a queue, or use Durable Functions — not one big function.
Create and run a function locally
Everything starts on your own machine. Install the Azure Functions Core Tools and create a new project:
npm install -g azure-functions-core-tools@3 --unsafe-perm true
func init MyFuncApp --python # or --dotnet / --node
cd MyFuncApp
func new --name HttpHello --template "HTTP trigger"
func start # runs locally on http://localhost:7071
The project contains a file called local.settings.json with your local settings and connection strings. It is already in .gitignore, and it should stay there.
An HTTP trigger with a queue output binding
Now something useful: an HTTP endpoint that receives an order and puts it in a queue for background processing. First we declare the bindings in HttpHello/function.json:
{
"bindings": [
{ "type": "httpTrigger", "direction": "in", "name": "req",
"authLevel": "function", "methods": ["post"] },
{ "type": "http", "direction": "out", "name": "$return" },
{ "type": "queue", "direction": "out", "name": "msg",
"queueName": "orders", "connection": "AzureWebJobsStorage" }
]
}
Then the code in HttpHello/__init__.py:
import json
import azure.functions as func
def main(req: func.HttpRequest, msg: func.Out[str]) -> func.HttpResponse:
order = req.get_json()
if "id" not in order:
return func.HttpResponse("missing id", status_code=400)
msg.set(json.dumps(order)) # goes to the 'orders' queue, no SDK code needed
return func.HttpResponse(f"queued {order['id']}", status_code=202)
Notice there is no storage SDK, no connection handling and no retry logic in the code. The output binding takes care of all of it.
Triggers you will use most
| Trigger | Runs when | Typical use |
|—|—|—|
| HTTP | A request arrives | Webhooks, small APIs |
| Timer | A CRON schedule fires | 0 */5 * * * * = every 5 minutes (note the first field is seconds) |
| Queue Storage | A new message arrives | Background jobs |
| Blob Storage | A file is created or updated | Thumbnails, file processing |
| Event Grid | An Azure event happens | Reacting to resource changes |
| Cosmos DB | The change feed has new items | Syncing data, materialized views |
Deploy to Azure
Once the function works locally, we create the Function App in Azure and publish:
az functionapp create -g rg-func -n myfuncapp-$RANDOM \
--storage-account <storage-name> --consumption-plan-location westeurope \
--runtime python --runtime-version 3.8 --functions-version 3 --os-type linux
func azure functionapp publish <function-app-name>
After publishing, the output shows the URL of the function, including the function key.
Security: choose the right auth level
anonymous— anyone can call it. Use it only for public webhooks that you validate yourself.function— the caller needs the function key (?code=...or thex-functions-keyheader). This is the sensible default.admin— needs the master key. Never share it.
Security note: Function keys are shared secrets, not user identity. If you need real user authentication, put App Service Authentication or API Management in front of the function.
Keep it small
Functions let you focus on the small piece of logic in the middle: triggers start your code, bindings move data in and out. Pick the hosting plan deliberately, keep functions small and idempotent (a queue message can arrive more than once), watch the poison queue, and switch on Application Insights from day one. More in the official Azure Functions documentation.