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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set azure-py-functionscd pulumi-examples/azure-py-functionsThis 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#
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
Log in to the Azure CLI (you will be prompted to do this during deployment if you forget this step):
Terminal window az login -
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 -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Deploy the stack:
Terminal window pulumi upType 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 createdOutputs: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 createdDuration: 50s -
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:
pulumi destroypulumi stack rm