Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Deploying serverless applications with Azure Functions

A minimal Azure Native Function in Python with Pulumi program

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set azure-py-functions
cd pulumi-examples/azure-py-functions

This example deploys an Azure Function App with HTTP-triggered serverless functions written in Python.

The application settings configure the app to run on Python 3 and to deploy a specified zip file to the Function App. The app will download the file, extract the code from it, discover the functions, and run them. We’ve prepared this zip file for you to get started faster; you can find its source code here. The code contains a single HTTP-triggered Azure Function. See app/README.md for an optional walkthrough of building the function project yourself.

Prerequisites#

  1. Install Pulumi
  2. Configure Azure credentials
  3. Install Python

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Log in to the Azure CLI (you will be prompted to do this during deployment if you forget this step):

    Terminal window
    az login
  3. Set the Azure region to deploy into. Choose any Azure region that supports the services used in this example (see this list of available regions):

    Terminal window
    pulumi config set azure-native:location eastus2
  4. Install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  5. Deploy the stack:

    Terminal window
    pulumi up
    Type Name Status
    + pulumi:pulumi:Stack azure-py-functions-dev created
    + ├─ azure-native:resources:ResourceGroup resourcegroup_functions_py created
    + ├─ azure-native:web:AppServicePlan consumption-plan created
    + ├─ azure-native:storage:StorageAccount storageaccount created
    + └─ azure-native:web:WebApp functionapp created
    Outputs:
    consumptionplan : "consumption-plan7b9df5ed"
    endpoint : "https://functionappfe054af4.azurewebsites.net/api/HelloWithPython"
    function_app : "functionappfe054af4"
    primarystoragekey : "[secret]"
    resourcegroup : "resourcegroup_functions_py4eba2bf2"
    storageaccount : "storageaccounta6b2e431"
    storageaccountkeys : "[secret]"
    storageconnectionstring: "[secret]"
    Resources:
    + 5 created
    Duration: 50s
  6. Check the deployed function endpoint via pulumi stack output, then open it in a browser or curl it:

    Terminal window
    curl "$(pulumi stack output endpoint)"
    Hello from Python in Pulumi! You have stood up a serverless function in Azure!

Cleaning up#

Once you are finished, you can destroy your stack and remove it to avoid incurring any additional cost:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.