Introduction

In modern cloud-based applications, scalability and cost efficiency are critical. Instead of managing servers, we can use serverless computing .

This is where Azure Functions come in.

Microsoft provides Azure Functions as a serverless compute service that allows you to run code on-demand without managing infrastructure.

In this article, we will learn:

What is Azure Functions?

Azure Functions are a serverless computing service that allows developers to run code in response to events without managing infrastructure.

Key benefits include:

Azure Functions follows an event-driven architecture , where functions execute automatically when specific events occur.

It follow the event-driven architecture.

Azure Function vs Azure App Service

FeatureAzure FunctionsAzure App Service
PurposeEvent-driven serverless computingHost full web applications and APIs
InfrastructureFully serverlessManaged servers
ScalingAutomatic scaling based on eventsManual or automatic scaling
BillingPay only when code runsPay for the running instance
Best forBackground jobs, event processingWeb apps, APIs, microservices
Execution modelTrigger basedRequest based
Cold startPossible (in consumption plan)No cold start
RuntimeSmall functionsFull application runtime

How Azure Functions Work

Azure Functions works using the following:

An event that starts the function.

Connects to external services (Blob, Queue, Cosmos DB, etc.)

Your actual business logic.

Types of Triggers

Here are commonly used triggers:

HTTP → API calls
Blob → File uploads
Queue → Background tasks
Timer → Scheduled jobs
Event Hub → Streaming data
Service Bus → Enterprise messaging

Creating a Blob Trigger Function in .NET 8

Diagram explanation before coding

  
Azure Blob Storage (practice-container)
            ↓
Azure Function (Blob Trigger)
            ↓
Process File
(Check if file is PDF)
            ↓
Azure Blob Storage (processed-container)
  

Open Visual studio and create the new project Azure Functions

STEP 1 — Click Next

On this screen:
Select Azure Functions
Click Next

S1

Configure Project

You'll see the project configuration screen.

Fill like this:

Click Create

S2

If needed, please check this. Article Azure Blob

Now Visual Studio will ask:

Then click Create

Choose:

S4

Visual Studio will:

This is the correct professional setup

  
    using System.IO;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace BlobToApiFunction
{
    public class Function1
    {
        private readonly ILogger<Function1> _logger;
        private readonly string _connectionString;

        public Function1(ILogger<Function1> logger)
        {
            _logger = logger;
            _connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
        }

        [Function(nameof(Function1))]
        public async Task Run(
            [BlobTrigger("practice-container/{name}", Connection = "AzureWebJobsStorage")]
            Stream stream,
            string name)
        {
            _logger.LogInformation($"Blob received: {name}");

            if (!name.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
            {
                _logger.LogWarning("File is not a PDF. Ignoring...");
                return;
            }

            var blobServiceClient = new BlobServiceClient(_connectionString);

            var sourceContainer = blobServiceClient.GetBlobContainerClient("practice-container");
            var destinationContainer = blobServiceClient.GetBlobContainerClient("processed-container");

            var sourceBlob = sourceContainer.GetBlobClient(name);
            var destinationBlob = destinationContainer.GetBlobClient(name);

            // Copy blob
            await destinationBlob.StartCopyFromUriAsync(sourceBlob.Uri);

            _logger.LogInformation("Blob copied to processed-container.");

            // Delete original blob
            await sourceBlob.DeleteAsync();

            _logger.LogInformation("Original blob deleted from practice-container.");
        }
    }
}
  

Configure local.settings.json

  
    {
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "YOUR_STORAGE_CONNECTION_STRING",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}
  

Storage Account → Access Keys

Run the Function

Click Start (F5)

Now:

  1. Go to Azure Portal

  2. Open your Blob container → uploads

  3. Upload any file

Your function will trigger locally.

You'll see logs in Visual Studio output window.

Configure Azure Function (Cloud)

Go to Azure Portal → Create → Function App

SA-01

Basics

SA-02

Click Review + Create

Publish the Azure Function using Visual Studio.

Open Visual Studio

Right-click your project
Publish

S6

Azure Function App (Windows)
Select your created app

Click Publish

Wait until it says: Publish succeeded

After Publishing (Very Important)

Go to the Azure Portal:

Function App →
Settings → Environment Variables

Check if:

  
    AzureWebJobsStorage
  

is automatically added.

If NOT:

Go to your Storage Account → Access keys → Copy Connection String →

Paste into:

  
    AzureWebJobsStorage
  

Save → Restart Function App

Upload a PDF into:

  
    practice-container
  

Go to:

Function App → Functions → Function1 → Monitor

You should see execution logs.

Conclusion

Azure Functions provide a powerful serverless solution that enables developers to build scalable and cost-efficient applications.

Key advantages include:

Azure Functions integrate seamlessly with many Azure services, making them a great choice for event-driven architectures.

You can Join me on LinkedIn to follow my learning journey.

Thank you so much for your time. Happy Coding !!