For this tutorial, we will create azure function using Azure Portal, however, this can also be created directly from VSCode, Az Cli etc.

Creating Azure Function App using Azure Portal

  1. Select resource group az-func-demo-wus
  2. Click on +Create button in overview tab.
  3. Search for Function App in marketplace and click create
  4. In Create Function App page:
    1. Ensure right subscription and resource group are selected.
    2. Function App name: Provide a unique name to Azure Function. Azure Function name are globally unique. I have selected function-demo.
    3. Publish: code
    4. Runtime stack: Python
    5. Version: 3.9
    6. Region: West US
    7. Operating System: Linux
    8. Plan Type: Consumption
  5. Skip Hosting tab
  6. Skip Networking tab
  7. Under Monitoring tab, ensure Application Insight is enabled.
  8. Under Deployment tab, link Github repository that we created.
  9. Click Review+Create
  10. Wait for Azure Deployment to complete.

Refresh VS Code for Azure Function App

  1. Click on Azure extension > Resources > Function App > Click on Refresh.
If refresh does not work, Try re-authenticating to Azure account from VS Code. Press Cmd+Shift+P and select Azure: Sign Out and then login.

At this point, we have Azure Function App created. Now it is the time to create a Function.

Azure Function App is collection of Function. A Function can be treated as single API.

Create Function from VS Code

  1. Click on Azure extension > Workspace > Click on + icon > Select Create HTTP Function

  2. Select language as Python

  3. Select Python interpreter as python3.9

  4. Provide a Name for Function. Scope of this name is within Function App. Hence, it should only be unique within Function App but not globally. Lets name it functiondemo

  5. VS Code should start creating virtual Environment and skeleton code for Function. We will see following directory structure or similar.

    .
    ├── README.md
    ├── host.json
    ├── local.settings.json
    ├── requirements.txt
    └── functiondemo
        ├── __init__.py
        ├── function.json
        └── sample.dat
    
  6. Lets add a .gitignore file and add .vscode, .venv, __pycache__ to it.

  7. Click on Run Menu > Run Without Debugging. This should start function locally with an API endpoint similar to functiondemo: [GET,POST] http://localhost:7071/api/functiondemo

  8. Verify if we are getting response from function endpoint locally using http://localhost:7071/api/functiondemo

  9. Once verified, Push the code to GitHub origin. This should trigger GitHub Action to deploy sample code to Azure Function App and create a function with name functiondemo

    git add .
    git status
    git commit -m "First Commit"
    git push
    
  10. Once GitHub Action is completed, verify response using Azure Function URL. If Azure Function url is https://function-demo.azurewebsites.net, then append /api/functiondemo to test. For example: https://function-demo.azurewebsites.net/api/functiondemo