Azure Function Deployment Guide
|
|
Azure Function Deployment Guide (Visual Studio Code)
Deploying Azure Functions is surprisingly smooth — whether you're using Visual Studio, VS Code, or Azure CLI. Here's a step-by-step guide using Visual Studio Code, which is ideal for C# developers.
🛠 Prerequisites
- Visual Studio Code (latest version)
- .NET SDK
- Azure Functions extension for VS Code
- Azure CLI installed
- Azure subscription (free or paid)
🚀 Step-by-Step: Deploy Azure Function (HTTP Trigger)
Step 1: Create a New Azure Function Project
- Open Visual Studio Code.
- Press Ctrl+Shift+P → Select Azure Functions: Create New Project.
- Choose a folder, language (C#), and trigger type (HTTP Trigger).
- Name your function (e.g.,
HelloFunction) and set access level to Function.
Step 2: Write Your Function Code
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
public class HelloFunction
{
private readonly ILogger _logger;
public HelloFunction(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HelloFunction>();
}
[Function("HelloFunction")]
public HttpResponseData Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Hello from Azure Function!");
return response;
}
}
Step 3: Test Locally
- Press F5 to run the function locally.
- Visit
http://localhost:7071/api/HelloFunction in your browser.
- You should see: Hello from Azure Function!
Step 4: Sign in to Azure
- Open terminal in VS Code.
- Run:
az login
- Follow the browser prompt to authenticate.
az login
Follow the browser prompt to authenticate.
Step 5: Create a Function App in Azure
az functionapp create --resource-group MyResourceGroup \
--consumption-plan-location eastus \
--runtime dotnet \
--functions-version 4 \
--name MyUniqueFunctionAppName \
--storage-account mystorageaccountname
Step 6: Deploy Your Function
- Press Ctrl+Shift+P → Select Azure Functions: Deploy to Function App.
- Choose your subscription and Function App name.
- Wait for deployment to complete.
Step 7: Test in Azure
- Visit:
https://<your-function-app>.azurewebsites.net/api/HelloFunction
- You should see: Hello from Azure Function!
✅ Summary
| Step |
Action |
| 1 |
Create project in VS Code |
| 2 |
Write function code |
| 3 |
Test locally |
| 4 |
Login to Azure |
| 5 |
Create Function App |
| 6 |
Deploy from VS Code |
| 7 |
Test live endpoint |
Pro Tip
You can automate deployment using GitHub Actions or Azure DevOps for CI/CD pipelines.