Azure 11: Azure Functions (Serverless)
easy⏱ 5 mincourseazure
Serverless with Azure Functions
Triggers start execution: HTTP, Timer (CRON), Blob, Queue, Event Grid, Cosmos DB change feed. Bindings connect to services declaratively. Plans: Consumption (auto-scale, pay-per-execution), Premium (pre-warmed, VNet), Dedicated (App Service plan).
import { app, HttpRequest, HttpResponseInit } from '@azure/functions';
app.http('hello', {
methods: ['GET'],
handler: async (req: HttpRequest): Promise<HttpResponseInit> => {
const name = req.query.get('name') || 'World';
return { body: 'Hello, ' + name + '!' };
}
});
Build a Function App simulator
Create a FunctionApp class with register(name, trigger, handler) and invoke(name, event). Register HTTP, Timer, and Queue functions. Invoke each and log outputs.
Quiz: Function Triggers
How many triggers can one Azure Function have? Exactly one. But it can have multiple input and output bindings.