Microsoft Azure · Compute

Azure Functions

Azure Functions runs small pieces of code in response to events — an HTTP request, a new file, a queue message, a timer — without managing servers.

Intermediate 5 min Lesson 8 of 28
Before you start:Azure App Service
0/28 in Microsoft Azure
On this page · 5 min · Intermediate

Learning objectives#

  • Explain triggers and bindings
  • Write an HTTP-triggered function
  • Choose a hosting plan
  • Know when serverless fits

Explanation#

A trigger starts a function: HTTP, Timer, Blob Storage, Queue Storage, Service Bus, Cosmos DB change feed and more. Bindings connect inputs and outputs declaratively.

Hosting plans: Flex Consumption (recommended serverless plan — scales to zero, pay per use, with optional always-ready instances), Premium (pre-warmed instances, VNet access) and Dedicated (runs on an App Service plan).

Scaling to zero saves money but can cause a cold start — a short delay when a new instance spins up.

Functions suit event-driven, short-running jobs. Long-running or constantly busy services are often cheaper on App Service or Container Apps.

Code example: HTTP function (Node.js v4 model)#

JavaScriptsrc/functions/hello.js Illustrative
const { app } = require('@azure/functions');


app.http('hello', {
  methods: ['GET'],
  authLevel: 'anonymous',
  handler: async (request, context) => {
    const name = request.query.get('name') ?? 'world';
    context.log(`Greeting ${name}`);
    return { body: `Hello, ${name}!` };
  },
});


// Run locally:   func start
// Deploy:        func azure functionapp publish <function-app-name>
Expected output
GET http://localhost:7071/api/hello?name=Asha
Hello, Asha!

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. app.http registers an HTTP-triggered function named hello.
  2. The handler reads a query-string parameter with a default.
  3. context.log writes to the function logs (and Application Insights).
  4. Returning { body } sends the HTTP response; the Functions host maps the route /api/hello.

Real-world use case#

Resize images when they are uploaded to Blob Storage, send a daily report on a timer, or process orders from a queue.

Common mistakes#

Long-running work in an HTTP function

HTTP requests have time limits. Return quickly and hand off long work to a queue or Durable Functions.

Ignoring cold starts for user-facing APIs

Use always-ready instances or the Premium plan when latency matters.

Best practices#

  • Keep functions small and stateless
  • Use managed identity for connections
  • Use queues for retries and spikes
  • Monitor with Application Insights

Remember this#

Trigger = what starts it. Binding = what it reads/writes.

Serverless = scale to zero, pay per run.

Short and event-driven → Functions. Always busy → App Service or containers.

Practice exercise#

Your task: Change the function so it returns JSON: { message: "Hello, Asha!" }.

Show solution
JavaScript Illustrative
return { jsonBody: { message: `Hello, ${name}!` } };

Mini quiz#

Azure Functions quizMultiple choice Question 1 of 2

What starts an Azure Function?

Score so far: 0/0

Want more? Practise all Microsoft Azure MCQs · Microsoft Azure interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.