Azure Functions: Complete Guide for Developers and Solution Architects
Azure Functions is one of Microsoft's most powerful serverless offerings. It enables developers to run code on demand without worrying about infrastructure, servers, operating systems, patching, or scaling.
In this article, I summarize everything I learned about Azure Functions while building and deploying Java-based functions integrated with Azure API Management (APIM), Microsoft Entra ID, and Microsoft Graph.
What is Azure Function?
Azure Functions is a serverless compute service that allows developers to execute code in response to events without managing infrastructure.
Microsoft automatically handles:
- Server provisioning
- Operating system management
- Patching
- Scaling
- Availability
- Monitoring
Developers can focus entirely on writing business logic.
Traditional Application
Application
↓
Virtual Machine
↓
Operating System
↓
Infrastructure
Managed by Developer
Azure Function
Application
↓
Azure Functions Platform
Managed by Azure
Why Use Azure Functions?
1. Serverless Computing
No virtual machines need to be managed. Developers deploy code and Azure executes it automatically.
2. Automatic Scaling
10 Requests
↓
1 Function Instance
1000 Requests
↓
Multiple Function Instances
Scaling happens automatically.
3. Pay for What You Use
On Consumption and Flex Consumption plans:
- No requests = No cost
- Pay only when code executes
4. Event Driven Architecture
Functions execute when specific events occur.
Event
↓
Azure Function
↓
Business Logic
Common Azure Function Use Cases
- REST APIs
- Graph API integrations
- File processing
- Scheduled jobs
- Background processing
- Data transformations
- Service Bus consumers
- Microservice components
- Webhook endpoints
- IoT processing
Types of Azure Function Triggers
Every Azure Function starts with a trigger. A trigger defines what causes the Function to execute.
1. HTTP Trigger
Most commonly used trigger.
Browser
↓
HTTP Request
↓
Azure Function
Java Example:
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS
)
Use Cases:
- REST APIs
- Webhook endpoints
- Authentication services
- Microservices
2. Timer Trigger
Schedule
↓
Azure Function
Example:
Every Day 2 AM
Use Cases:
- Nightly processing
- Reports
- Cleanup jobs
- Data synchronization
3. Blob Trigger
Blob Uploaded
↓
Azure Function
Use Cases:
- Image processing
- PDF processing
- File validation
4. Queue Trigger
Storage Queue
↓
Azure Function
Use Cases:
- Asynchronous processing
- Decoupled systems
5. Service Bus Trigger
Azure Service Bus
↓
Azure Function
Use Cases:
- Enterprise integrations
- Microservices
- Event driven systems
6. Event Grid Trigger
Resource Event
↓
Event Grid
↓
Azure Function
7. Cosmos DB Trigger
Document Updated
↓
Azure Function
8. Event Hub Trigger
IoT Events
↓
Event Hub
↓
Azure Function
Azure Function Hosting Plans
Consumption Plan
Classic serverless model.
No Requests
↓
Scale to Zero
Flex Consumption Plan
New generation serverless hosting plan.
Benefits:
- Faster startup times
- Improved networking support
- Enhanced scaling
Premium Plan
For enterprise workloads.
Benefits:
- No cold starts
- VNET Integration
- Higher throughput
App Service Plan
Dedicated infrastructure.
App Service Plan
↓
Azure Function
Ways to Develop Azure Functions
Visual Studio Code
Most popular choice.
Extensions:
- Azure Functions Extension
- Azure Tools Extension
Visual Studio
Best for .NET Developers.
IntelliJ IDEA
Popular among Java developers.
Maven
Common approach for Java Azure Functions.
mvn azure-functions:run
Ways to Deploy Azure Functions
1. Azure Portal
Manual deployment through Azure Portal. Useful for experiments and proofs of concept.
2. VS Code Deployment
Right Click Function App
↓
Deploy
3. Maven Deployment
mvn azure-functions:deploy
Preferred deployment method for Java projects.
4. ZIP Deployment
az functionapp deployment source config-zip
Useful for scripted deployments.
5. Azure CLI Deployment
az functionapp create
az functionapp deploy
6. GitHub Actions
GitHub
↓
Build
↓
Deploy
↓
Azure Function
7. Azure DevOps Pipelines
Build Pipeline
↓
Release Pipeline
↓
Azure Function
8. Terraform
Infrastructure as Code deployment.
Ways to Test Azure Functions Locally
1. Azure Functions Core Tools
func start
or
mvn azure-functions:run
2. Browser Testing
For GET requests:
http://localhost:7071/api/HttpExample?name=Vikas
3. Curl
curl "http://localhost:7071/api/HttpExample?name=Vikas"
4. Postman
Most common testing tool.
5. Bruno
Lightweight API testing tool.
6. VS Code Debugger
Supports breakpoints and step-by-step debugging.
7. Unit Testing
JUnit
Mockito
Useful for testing business logic.
My Java Azure Function Example
I built and deployed the following Java Azure Function.
@FunctionName("HttpExample")
public HttpResponseMessage run(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
final String query =
request.getQueryParameters().get("name");
final String name =
request.getBody().orElse(query);
if (name == null) {
return request.createResponseBuilder(
HttpStatus.BAD_REQUEST)
.body("Please pass a name")
.build();
}
return request.createResponseBuilder(
HttpStatus.OK)
.body("Hello, " + name)
.build();
}
Testing Through Browser
Once deployed, the Function can be called through a browser.
https://myfunction.azurewebsites.net/api/HttpExample?name=Vikas
Response:
Hello, Vikas
Calling Azure Function Using Postman
GET Request Example
Method:
GET
URL:
https://myfunction.azurewebsites.net/api/HttpExample?name=Vikas
Response:
Hello, Vikas
POST Request Example
Method:
POST
Headers:
Content-Type: text/plain
Body:
Vikas
Calling Azure Function Using Bearer Tokens
I also built a Function that accepts Authorization headers.
Authorization: Bearer eyJ...
The Function:
- Receives the JWT token
- Decodes the token
- Extracts the App ID claim
- Calls Microsoft Graph
Calling Azure Function Through APIM
One interesting scenario I implemented was:
Client
↓
Azure API Management
↓
Azure Function
↓
Microsoft Graph
APIM policy:
<send-request
mode="new"
response-variable-name="userContext">
<set-url>
https://myfunction.azurewebsites.net/api/ValidateApp
</set-url>
<set-method>POST</set-method>
<set-header
name="Authorization"
exists-action="override">
<value>
@(context.Request.Headers
.GetValueOrDefault("Authorization"))
</value>
</set-header>
</send-request>
Key Benefits of Azure Functions
- No infrastructure management
- Serverless architecture
- Automatic scaling
- Rapid development
- Low operational cost
- Strong Azure integration
- Easy API creation
- Event-driven processing
- Supports Java, .NET, Python, Node.js, and PowerShell
Key Learnings
- Azure Functions are ideal for event-driven workloads.
- Java Azure Functions are straightforward to develop and deploy.
- Azure Functions integrate seamlessly with APIM.
- Bearer tokens can be passed through APIM to Functions.
- Microsoft Graph can be called from Functions for advanced authorization patterns.
- Managed Identity is the preferred authentication mechanism for Azure services.
- Functions are excellent building blocks for microservices and integration solutions.
Conclusion
Azure Functions provide a modern serverless platform for building APIs, integrations, automation, and event-driven workloads. Developers can focus on business logic while Azure manages infrastructure, scaling, availability, and operations.
Whether you are building REST APIs, integrating Microsoft Graph, processing files, or implementing enterprise authorization solutions behind APIM, Azure Functions provide a powerful and cost-effective way to deliver cloud-native applications.
No comments:
Post a Comment