Azure Classroom Series – 10/Jan/2020

Azure Functions Sample in Python

  • Ensure 64-bit Python is installed.
  • Create a new directory for azure functions mkdir azurefunctionssamples && cd azurefunctionssamples
  • Create an azure functions project
func init myazurefunctionssample --language python
  • Create a new function with Http Trigger
func new --name HttpTrigger --template "HTTP trigger"
  • To run azure function locally on your machine, open cmd or powershell as admin and execute func host start
  • Stop the process by entering ctrl+c in powershell
  • Now in the azurefunctionssamples\requirements.txt ensure you have following
  • From powershell terminal after cd into azurefunctionssamples
pip install -r requirements.txt
  • If azure cli is not installed install as suggested over here
  • For Python SDK usage refer here
  • Get Azure Credentials by executing the following commands
az ad sp create-for-rbac --query "{ client_id: appId, client_secret: password, tenant_id: tenant }"

az account show --query "{ subscription_id: id }"
  • Navigate to HttpTrigger and make the changes as shown below
import logging
import os

import azure.functions as func
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient

def main(req: func.HttpRequest) -> func.HttpResponse:'Python HTTP trigger function processed a request.')
    subscription_id = os.environ.get(
    'AZURE_SUBSCRIPTION_ID','<your-subcription-id>') # your Azure Subscription Id
    credentials = ServicePrincipalCredentials(
    client = ResourceManagementClient(credentials, subscription_id)
    name = ""
    for item in client.resource_groups.list():
        name = name + + '\n'
    #name = req.params.get('name')
    if not name:
            req_body = req.get_json()
        except ValueError:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello {name}!")
        return func.HttpResponse(
             "Please pass a name on the query string or in the request body",

Azure Logic Apps

  • Before defining Logic App, Lets create one
  • Navigate to Home => All Services => Logic and create the Logic App.
  • Once you navigate to resource, a designer screen is opened where the workflow of your logic can be designed
  • So, Azure Logic Apps is serverless implementation of Workflow.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin