Provision and publish a bot
APPLIES TO: SDK v4
This article describes how to use the Azure CLI to create resources for your bot, prepare your bot for deployment, and deploy your bot to Azure.
This article assumes that you have a bot ready to be deployed. For information on how to create a simple echo bot, see Create a bot with the Bot Framework SDK. You can also use one of the samples provided in the Bot Framework Samples repository.
This article creates an Azure Bot resource for your bot. Existing bots that use a Web App Bot resource or a Bot Channels Registration resource will continue to work, but you can't create new bots that use these resource types.
For Java bots, install Maven.
This process uses two Azure Resource Manager templates (ARM templates) to create resources for your bot.
To use the Azure CLI to provision and publish bots, you need:
An Azure account that has an active subscription. Create a free account.
For your programming language, use the following version of the Azure CLI. Some steps won't work with later versions of the CLI.
If your bot uses additional resources, such as a storage service or language services, these need to be deployed separately.
Plan your deployment
Before you begin, make these decisions.
|How you will manage the identities of your bot resources in Azure||You can use a user-assigned managed identity, a single-tenant app registration, or a mutli-tenant app registration. For more information, see Create an identity resource.|
|In which resource group or resource groups you'll create your bot resources||Until you're familiar with this process, we recommend using one resource group. For more information, see Manage Azure resources.|
|Whether your bot will be regional or global||For information about regional bots, see Regionalization in Azure Bot Service.|
Your bot identity can be managed in Azure in a few different ways.
- As a user-assigned managed identity, so that you don't need to manage the bot's credentials yourself.
- As a single-tenant app.
- As a multi-tenant app.
|Multi-tenant||Azure Bot Service, all Bot Framework SDK languages, Composer, the Emulator, and ngrok|
Python bots can't be deployed to a resource group that contains Windows services or bots. However, multiple Python bots can be deployed to the same resource group. Create other services, such as LUIS or QnA Maker, in a different resource group.
Before you can deploy your bot, you create (or provision) the Azure resources it will need. For some of the steps, you can use an existing resource or create a new one.
You may find it helpful to decide ahead of time on the names of the new resources you will create and the names of the existing resources you will use. Your bot will use these types of resources.
- The Azure subscription that you'll use to provision, publish, and manage the bot
- One or more resource groups
- A user-assigned managed identity or an Azure Active Directory app registration
- An App Service Plan resource
- An App Service resource
- An Azure Bot resource
Information used across resources
As you create resources in Azure, Azure will generate or request IDs, passwords, and other information that you will need in later steps. The following table lists the information beyond resource names you'll need to record, in which step it's generated, and in which steps it's used.
Many of these IDs and passwords are sensitive information. For information about common security guidelines, see Bot Framework security guidelines.
Sign in and select subscription
Open a command window.
Sign in to Azure.
- A browser window will open. Complete the sign-in process.
- On success, the command outputs a list of the subscriptions your account has access to.
To set the subscription to use, run:
az account set --subscription "<subscription>"
For <subscription>, use the ID or name of the subscription to use.
If you'll create a user-assigned managed identity or a single-tenant bot, record the
tenantIdfor the subscription. You'll use the tenant ID in the following steps.
If you need to work in a non-public cloud, see Azure cloud management with the Azure CLI.
Create resource groups
If you don't already have an appropriate resource group, use the
az group create command to create the new resource groups you need.
az group create --name "<group>" --location "<region>"
|name||The name of the resource group to create.|
|location||The region in which to create the resource group.|
Currently, regionalized bots are only available for Europe. For a regionalized bot, use "westeurope" for the location.
For more information, see How to manage Azure resource groups with the Azure CLI.
Create an identity resource
To create a user-assigned managed identity, use the
az identity createcommand. On success, the command generates JSON output.
az identity create --resource-group "<group>" --name "<identity>"
Option Description resource-group The name of the resource group in which to create the identity. name The name of the identity resource to create.
For more information, see the az identity reference.
Record values you'll need in later steps.
- The resource group name for the identity resource
- The name of the identity resource
clientIdfrom the command output
Create resources with ARM templates
Create the App Service and the Azure Bot resources for your bot.
Both steps use an ARM template and the
az deployment group create Azure CLI command to create the resource or resources.
Create an App Service resource for your bot. The App service can be within a new or existing App Service Plan.
For detailed steps, see Use Azure CLI to create an App Service.
Create an Azure Bot resource for your bot.
For detailed steps, see Use Azure CLI to create or update an Azure Bot.
You can do these steps in either order. However, if you create your Azure Bot first, you'll need to update its messaging endpoint after you create your App Service resource.
Update project configuration settings
Bot identity information
Follow these steps to add identity information to your bot's configuration file. The file differs depending on the programming language you use to create the bot.
|C#||appsettings.json||Supports all three application types for managing your bot's identity.|
|Java||application.properties||Only supports multi-tenant bots.|
|Python||config.py||Only supports multi-tenant bots. Provide the identity properties as arguments to the
The identity information you need to add depends on the bot's application type. Provide the following values in your configuration file.
||The client ID of the user-assigned managed identity.|
||Not applicable. Leave this blank for a user-assigned managed identity bot.|
||The tenant ID of the user-assigned managed identity.|
Prepare your project files
Prepare your project files before you deploy your bot.
Switch to your project's root folder. For C#, the root is the folder that contains the .csproj file.
Do a clean rebuild in release mode.
If you haven't done so before, run
az bot prepare-deployto add required files to the root of your local source code directory. This command generates a
.deploymentfile in your bot project folder.
az bot prepare-deploy --lang Csharp --code-dir "." --proj-file-path "<my-cs-proj>"
Option Description lang The language or runtime of the bot. Use
code-dir The directory to place the generated deployment files in. Use your project's root folder. Default is the current directory. proj-file-path The path to the .csproj file for your bot, relative to the
Within your project's root folder, create a zip file that contains all files and subfolders.
Publish your bot to Azure
At this point, you are ready to deploy code for your bot to your App Service resource.
This step can take a few minutes to complete. Also it can take a few more minutes between when the deployment finishes and when your bot is available to test.
Run the following command from the command line to perform deployment using the Kudu zip push deployment for your app service (web app).
az webapp deployment source config-zip --resource-group "<resource-group-name>" --name "<name-of-app-service>" --src "<project-zip-path>"
|resource-group||The name of the Azure resource group that contains your bot.|
|name||Name of the app service you used earlier.|
|src||The absolute or relative path to the zipped project file you created.|
By default, this command deploys to the production slot. Use the optional
--slot parameter to specify a different slot.
For more information, see the az webapp deployment source config-zip command reference.
Test in Web Chat
- In your browser, navigate to the Azure portal.
- Go to your bot resource.
- Open the Test in Web Chat pane.
- Interact with your deployed bot.
For more information about bot registration, see Register a bot with Bot Service.
Clean up resources
If you're not going to publish this application, delete the associated resources with the following steps:
- In the Azure portal, open the resource group for your bot.
- Select Delete resource group to delete the group and all the resources it contains.
- Enter the resource group name in the confirmation pane, then select Delete.
- If you created a single-tenant or multi-tenant app:
- Go to the Azure Active Directory blade.
- Locate the app registration you used for your bot, and delete it.
See these articles for more information about Azure applications and resources that are used to host a bot.
|Azure CLI||What is the Azure CLI?|
|Azure subscription management||How to manage Azure subscriptions with the Azure CLI|
|Azure regions||Regions and availability zones|
|Resource groups and resource management||Manage Azure resources|
|Managed identities||What are managed identities for Azure resources?|
|Single-tenant and multi-tenant apps||Tenancy in Azure Active Directory|
|Web applications||App Service|
|Compute resources for web applications||App Service plans|
|Azure Resource Manager templates (ARM templates)||What are ARM templates? and How to use Azure Resource Manager (ARM) deployment templates with Azure CLI|
|Azure billing||Billing and cost management|
Kudu assumes by default that deployments from .zip files are ready to run and don't require extra build steps during deployment, such as npm install or dotnet restore/dotnet publish.
It's important to include your built code with all necessary dependencies in the zip file being deployed; otherwise, your bot will not work as intended. For more information, see the Azure documentation on how to Deploy files to App Service.
Submit and view feedback for