Create Your First Azure Function

This guide will walk you through creating your very first Azure Function using the Azure portal. Azure Functions is a serverless compute service that lets you run code on-demand without explicitly provisioning or managing infrastructure.

Prerequisites

1. Azure Account

You need an active Azure subscription. If you don't have one, you can create a free account.

Steps to Create Your First Function

1. Navigate to the Azure Portal

Sign in to the Azure portal.

2. Create a Function App
  1. In the Azure portal, search for and select Function App.
  2. Click Create.
  3. On the Basics tab, configure the following settings:
    • Subscription: Select your Azure subscription.
    • Resource group: Create a new one or select an existing one.
    • Function App name: Enter a globally unique name.
    • Publish: Select Code.
    • Runtime stack: Choose your preferred language (e.g., .NET, Node.js, Python).
    • Version: Select the version of the runtime.
    • Region: Choose the Azure region closest to you.
  4. Click Review + create, then Create.

Wait for the Function App to be deployed. This may take a few minutes.

3. Create Your First Function
  1. Once your Function App is deployed, navigate to its resource page.
  2. In the left-hand menu, select Functions.
  3. Click Create.
  4. Under Template, select HTTP trigger - C# (or your preferred language and template).
  5. Provide a New Function Name, for example, MyHttpTrigger.
  6. Set the Authorization level to Anonymous for easy testing.
  7. Click Create.
4. Test Your Function
  1. After the function is created, select it from the list.
  2. In the function's overview page, click Get Function URL.
  3. Copy the URL provided. This is the endpoint for your function.
  4. Paste this URL into a web browser or use a tool like curl or Postman to make a GET request.

You should see a response like:

{ "name": "Azure Functions", "message": "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." }

You can also append a name to the URL to personalize the response, for example:

https://YOUR_FUNCTION_URL?name=YourName

The response will be:

Hello, YourName. This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.

Note: For security reasons, it's recommended to use a higher authorization level than Anonymous in production environments.

Tip: Explore other templates available in Azure Functions to build different types of serverless applications, such as timer triggers, queue triggers, and more.