0
0
Azurecloud~5 mins

Trigger types (HTTP, Timer, Blob, Queue) in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Triggers start your Azure Function automatically when something happens. They help your function respond to events like web requests, scheduled times, or new files.
When you want your function to run when someone visits a web URL (HTTP trigger).
When you need your function to run on a schedule, like every hour (Timer trigger).
When you want your function to run when a new file is added to Azure Blob Storage (Blob trigger).
When you want your function to run when a new message arrives in an Azure Storage Queue (Queue trigger).
Config File - function.json
function.json
{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": ["get", "post"]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

This file defines the trigger type and how the function is called.

bindings: Lists triggers and outputs.

httpTrigger: Starts function on HTTP request.

authLevel: Controls access (function means a key is needed).

methods: Allowed HTTP methods.

Commands
Create a new Azure Functions app with .NET runtime to start building functions.
Terminal
func init MyFunctionApp --worker-runtime dotnet
Expected OutputExpected
Creating new Azure Functions project in C#... Project created successfully.
--worker-runtime - Specifies the runtime language for the function app.
Create a new function with an HTTP trigger that requires a function key for access.
Terminal
func new --name HttpTriggerFunction --template "HTTP trigger" --authlevel function
Expected OutputExpected
Created new function 'HttpTriggerFunction' with HTTP trigger.
--template - Specifies the trigger type template.
--authlevel - Sets the authorization level for the HTTP trigger.
Start the function app locally to test the trigger and function behavior.
Terminal
func start
Expected OutputExpected
Functions runtime started. Listening on http://localhost:7071 Hit CTRL+C to exit.
Send an HTTP GET request to trigger the HTTP function and see the response.
Terminal
curl http://localhost:7071/api/HttpTriggerFunction?name=Azure
Expected OutputExpected
{"message":"Hello, Azure"}
Key Concept

If you remember nothing else from this pattern, remember: triggers automatically start your function when specific events happen.

Common Mistakes
Using the wrong trigger type for the event you want to respond to.
The function will not start because the trigger does not match the event source.
Choose the trigger type that matches your event, like HTTP for web requests or Timer for scheduled runs.
Not setting the correct authorization level for HTTP triggers.
Your function might be inaccessible or open to everyone unintentionally.
Set authLevel to 'function' or 'anonymous' based on your security needs.
Forgetting to start the function app locally before testing triggers.
You cannot test triggers if the function app is not running.
Always run 'func start' to launch the function app before sending events.
Summary
Initialize an Azure Functions app with the desired runtime.
Create functions with specific triggers like HTTP, Timer, Blob, or Queue.
Start the function app locally to test trigger responses.
Use the correct trigger type and authorization settings for your scenario.