Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

Provisioning Azure App Services to host your Hello World webapp

15 Mar 2023 🔖 beginner azure web development
💬 EN

Table of Contents

Thus far in this series, we’ve written the world’s tiniest webserver, added unit tests to its codebase, told Azure DevOps (“ADO”) Pipelines to auto-build a runnable web server for us each time we update our Git-tracked source code, and told ADO to fail the build process if the unit tests don’t pass.

Before we can ask friends to visit our new website, we’ll need to rent a webserver host from Microsoft Azure’s public cloud.

Azure App Service’s (“AAS’s”) Web Apps service (“AASWA”) is a great choice for a simple web server. Let’s rent ourselves two such resource instances:

  1. One to host our “production” website.
  2. Another to host a “nonproduction” website where we can play with new ideas in private.

Prerequisites

  1. Have an account in Azure.
  2. Log your computer’s command line into that Azure account.
  3. Determine the unique name of the Azure resource group that you’d like to create things within, and make sure it exists.
    • For this exercise, I created a brand new one named “my-hello-web-rg” inside my Azure account.

Note: In an enterprise context, your 2 AASWA resources might end up in two separate resource groups – one for production and one for nonproduction.

Luckily, in an enterprise setting, there’s probably another team worrying about this for you who will be provisioning your Azure resource group resources, Azure App Service Service Plan (“AASSP”) resources, and AASWA resources for you.

For the purpose of following tutorials in this series, we’re going to save ourselves time and provision the simplest architecture possible.


Provision 1 Service Plan resource

In my scripts below, be sure to substitute:

  1. my-hello-web-rg” if that’s not actually the name of your resource group.
  2. my-first-app-service-plan” if that’s not actually the name of the app service plan you’d like to create.

With Azure PowerShell

If ( `
    Get-AzAppServicePlan `
        -ResourceGroupName "my-hello-web-rg" `
        -Name "my-first-app-service-plan" `
) {} `
Else { `
    New-AzAppServicePlan `
        -ResourceGroupName "my-hello-web-rg" `
        -Name "my-first-app-service-plan" `
        -Location "centralus" `
        -Tier "F1" `
        -Linux; `
}

If you get an error of…

New-AzAppServicePlan: Operation returned an invalid status code 'Unauthorized'

…then Microsoft might still be out of “centralus” app service plans, which was an issue in the spring of 2023 as this article went to press.

Try something else like eastus or northcentralus or westus.

With the Azure CLI

In a Windows PowerShell command prompt

If ( `
    az appservice plan show `
        --resource-group "my-hello-web-rg" `
        --name "my-first-app-service-plan" `
) {} `
Else { `
    az appservice plan create `
        --resource-group "my-hello-web-rg" `
        --name "my-first-app-service-plan" `
        --location "centralus" `
        --sku "F1" `
        --is-linux; `
}

If you get an error of…

This region has a quota of 0 instances for your subscription. Try selecting different region or SKU.

…then Microsoft might still be out of “centralus” app service plans, which was an issue in the spring of 2023 as this article went to press.

Try something else like eastus or northcentralus or westus.

In a Linux-style command prompt

if [ \
    "[]" == $(az appservice plan list --query "[?resourceGroup=='my-hello-web-rg' && name=='my-first-app-service-plan']") \
]; \
then 
    az appservice plan create \
      --resource-group "my-hello-web-rg" \
      --name "my-first-app-service-plan" \
      --location "centralus" \
      --sku "F1" \
      --is-linux; \
fi;

Provision 2 Web App resources

In my scripts below, be sure to substitute:

  1. my-hello-web-rg” if that’s not actually the name of your resource group.
  2. my-first-app-service-plan” if that’s not actually the name of your app service plan.
  3. my-first-webapp-nonprod” if that’s not actually the name of the nonproduction app service web app you’d like to create.
  4. my-first-webapp-prod” if that’s not actually the name of the production app service web app you’d like to create.
  5. Central US” if that’s not actually the name of the region in which you’d like to create your web app (parameter helps make web app creation work in Azure PowerShell).
  6. NODE:18-lts” if that’s not actually the runtime for the codebase you’ll be deploying to your web app (parameter helps make web app creation work in the Azure CLI).

With Azure PowerShell

If ( `
    Get-AzWebApp `
        -ResourceGroupName "my-hello-web-rg" `
        -Name "my-first-webapp-nonprod" `
) {} `
Else { `
    New-AzWebApp `
        -ResourceGroupName "my-hello-web-rg" `
        -AppServicePlan "my-first-app-service-plan" `
        -Location "Central US" `
        -Name "my-first-webapp-nonprod"; `
} `
If ( `
    Get-AzWebApp `
        -ResourceGroupName "my-hello-web-rg" `
        -Name "my-first-webapp-prod" `
) {} `
Else { `
    New-AzWebApp `
        -ResourceGroupName "my-hello-web-rg" `
        -AppServicePlan "my-first-app-service-plan" `
        -Location "Central US" `
        -Name "my-first-webapp-prod"; `
}

If you get an error of…

New-AzWebApp: Operation returned an invalid status code 'NotFound'

…then perhaps the “Location” parameter value you picked doesn’t match the one you created your app service plan in.

Try matching it to the app service plan.

With the Azure CLI

In a Windows PowerShell command prompt

If ( `
    az webapp show `
        --resource-group "my-hello-web-rg" `
        --name "my-first-webapp-nonprod" `
) {} `
Else { `
    az webapp create `
        --resource-group "my-hello-web-rg" `
        --plan "my-first-app-service-plan" `
        --runtime "NODE:18-lts" `
        --name "my-first-webapp-nonprod"; `
} `
If ( `
    az webapp show `
        --resource-group "my-hello-web-rg" `
        --name "my-first-webapp-prod" `
) {} `
Else { `
    az webapp create `
        --resource-group "my-hello-web-rg" `
        --plan "my-first-app-service-plan" `
        --runtime "NODE:18-lts" `
        --name "my-first-webapp-prod"; `
}

In a Linux-style command prompt

if [ \
    "[]" == $(az webapp list --query "[?resourceGroup=='my-hello-web-rg' && plan=='my-first-app-service-plan' && name=='my-first-webapp-nonprod']") \
]; \
then 
    az webapp create \
      --resource-group "my-hello-web-rg" \
      --plan "my-first-app-service-plan" \
      --runtime "NODE:18-lts" \
      --name "my-first-webapp-nonprod"; \
fi; \
if [ \
    "[]" == $(az webapp list --query "[?resourceGroup=='my-hello-web-rg' && plan=='my-first-app-service-plan' && name=='my-first-webapp-prod']") \
]; \
then 
    az webapp create \
      --resource-group "my-hello-web-rg" \
      --plan "my-first-app-service-plan" \
      --runtime "NODE:18-lts" \
      --name "my-first-webapp-prod"; \
fi;

Posts in this series

--- ---