Azure Serverless Application
The Azure Serverless Application template scaffolds a Pulumi project that deploys an Azure Blob Storage account configured for static website hosting and an Azure Function for the application backend. The template ships with placeholder web and function content so the project deploys end to end out of the box.
Before you begin#
Make sure you’ve installed Pulumi and configured your Azure credentials.
Create a new project#
Create a new project using the template in the language of your choice:
mkdir my-serverless-app && cd my-serverless-apppulumi new serverless-azure-typescriptmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-azure-pythonmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-azure-gomkdir my-serverless-app && cd my-serverless-apppulumi new serverless-azure-csharpmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-azure-yamlmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-azure-hclpulumi new walks you through creating and configuring a new project and stack. A stack is an instance of a project and you can have many of them — dev, staging, prod — each with its own configuration settings. The template also includes some additional settings:
| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure region to deploy into | WestUS |
| sitePath | The path to the folder containing the website | ./www |
| appPath | The path to the folder containing the functions to be deployed | ./app |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set:
pulumi config set azure-native:location <value>pulumi config set sitePath <value>pulumi config set appPath <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure region to deploy into | WestUS |
| sitePath | The path to the folder containing the website | ./www |
| appPath | The path to the folder containing the functions to be deployed | ./app |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set:
pulumi config set azure-native:location <value>pulumi config set sitePath <value>pulumi config set appPath <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure region to deploy into | WestUS |
| sitePath | The path to the folder containing the website | ./www |
| appPath | The path to the folder containing the functions to be deployed | ./app |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set:
pulumi config set azure-native:location <value>pulumi config set sitePath <value>pulumi config set appPath <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure region to deploy into | WestUS |
| sitePath | The path to the folder containing the website | ./www |
| appPath | The path to the folder containing the functions to be deployed | ./app |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set:
pulumi config set azure-native:location <value>pulumi config set sitePath <value>pulumi config set appPath <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure region to deploy into | WestUS |
| sitePath | The path to the folder containing the website | ./www |
| appPath | The path to the folder containing the functions to be deployed | ./app |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set:
pulumi config set azure-native:location <value>pulumi config set sitePath <value>pulumi config set appPath <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure region to deploy into | WestUS2 |
| site_path | The path to the folder containing the website | ./www |
| app_path | The path to the folder containing the function to deploy | ./app |
| index_document | The file to use for top-level pages | index.html |
| error_document | The file to use for error pages | error.html |
pulumi config set:
pulumi config set azure-native:location <value>pulumi config set site_path <value>pulumi config set app_path <value>pulumi config set index_document <value>pulumi config set error_document <value>When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and holds the program: the resources it declares.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
Deploy the project#
Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.
pulumi upPulumi adds a random suffix to most resource names, so the resource group resource-group becomes something like resource-group8f3c2a1b. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
When it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist:
- siteURL
The HTTP URL of the static website.
- apiURL
The HTTP URL of the serverless function endpoint.
- siteURL
The HTTP URL of the static website.
- apiURL
The HTTP URL of the serverless function endpoint.
- siteURL
The HTTP URL of the static website.
- apiURL
The HTTP URL of the serverless function endpoint.
- siteURL
The HTTP URL of the static website.
- apiURL
The HTTP URL of the serverless function endpoint.
- originURL
The HTTP URL of the static website.
- apiURL
The HTTP URL of the serverless function endpoint.
- origin_url
The HTTP URL of the static website.
- api_url
The HTTP URL of the serverless function endpoint.
Read one any time with pulumi stack output <name>, or pass it to another command. This opens the website in your browser:
open $(pulumi stack output siteURL)open $(pulumi stack output siteURL)open $(pulumi stack output siteURL)open $(pulumi stack output siteURL)open $(pulumi stack output originURL)open $(pulumi stack output origin_url)The website’s button calls the function at the /data path. Call it from the terminal with curl; it prints the current time in milliseconds, like {"now": 1792591509000}. The first call can take a few seconds while the function starts.
curl -s $(pulumi stack output apiURL)/datacurl -s $(pulumi stack output apiURL)/datacurl -s $(pulumi stack output apiURL)/datacurl -s $(pulumi stack output apiURL)/datacurl -s $(pulumi stack output apiURL)/datacurl -s $(pulumi stack output api_url)/dataCustomize the project#
Projects created with the Serverless Application template expose the following configuration settings:
- sitePath
The path to the folder containing the files of the website. Defaults to
www, which is the folder included with the template.- appPath
The path to the folder containing the serverless functions to be deployed. Defaults to
app, which is also included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- sitePath
The path to the folder containing the files of the website. Defaults to
www, which is the folder included with the template.- appPath
The path to the folder containing the serverless functions to be deployed. Defaults to
app, which is also included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- sitePath
The path to the folder containing the files of the website. Defaults to
www, which is the folder included with the template.- appPath
The path to the folder containing the serverless functions to be deployed. Defaults to
app, which is also included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- sitePath
The path to the folder containing the files of the website. Defaults to
www, which is the folder included with the template.- appPath
The path to the folder containing the serverless functions to be deployed. Defaults to
app, which is also included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- sitePath
The path to the folder containing the files of the website. Defaults to
www, which is the folder included with the template.- appPath
The path to the folder containing the serverless functions to be deployed. Defaults to
app, which is also included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- site_path
The path to the folder containing the files of the website. Defaults to
./www, which is the folder included with the template.- app_path
The path to the folder containing the serverless functions to be deployed. Defaults to
./app, which is also included with the template.- index_document
The file to use for top-level pages. Defaults to
index.html.- error_document
The file to use for error pages. Defaults to
error.html.
All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, Pulumi.dev.yaml) or by changing their values with pulumi config set.
pulumi config set sitePath ../my-existing-website/buildpulumi uppulumi config set sitePath ../my-existing-website/buildpulumi uppulumi config set sitePath ../my-existing-website/buildpulumi uppulumi config set sitePath ../my-existing-website/buildpulumi uppulumi config set sitePath ../my-existing-website/buildpulumi uppulumi config set site_path ../my-existing-website/buildpulumi upChanging the error page#
The error page is what the website returns for a path it doesn’t have. Point it at the home page instead, then ask for a page that doesn’t exist. curl prints the home page, with What time is it?, in place of the template’s Oops! That page wasn't found.:
pulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output siteURL)no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output siteURL)no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output siteURL)no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output siteURL)no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output originURL)no-such-pagepulumi config set error_document index.htmlpulumi upcurl -s $(pulumi stack output origin_url)no-such-pageTo see what else you can add, browse the Azure Native provider in the Pulumi Registry.
Cleaning up#
You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:
pulumi destroyLearn more#
- Browse other architecture templates in the Templates gallery.
- Explore the Azure Native provider API docs in the Pulumi Registry.
- Walk through Pulumi from the ground up in Pulumi Tutorials.
- Read the latest Azure posts on the Pulumi blog.