microsoft / vscode-azureappservice

Azure App Service extension for VS Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureappservice
MIT License
111 stars 94 forks source link

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

Open mubranch opened 1 year ago

mubranch commented 1 year ago

When deploying a flask application in vscode via the Resources panel > Click '+' > Select static Web apps workflow show in this quickstart here: Python Flask Quickstart. I receive the error This region has quota of 0 instances for your subscription. Try selecting different region or SKU.

Screenshot:

Screenshot 2023-03-30 at 1 22 51 PM

In the portal activity log JSON for the failed resource update I see:

Screenshot 2023-03-30 at 1 27 37 PM

To circumvent this issue while still leveraging the VSCode extension. I leverage this workflow: Resources > Right click 'App Service' under my subscription title > Select 'Create new web app (advanced)' and manually set the region to EastUS.

Error repro'd with: Subscription type: Personal Pricing Tier: Free and Basic

alexweininger commented 1 year ago

Do you happen to know what region the app was being deployed to when it failed? I have a feeling it was Central US. In order to confirm that, could you try the "Create new web app (Advanced)" again and select Central US for the location? I suspect it will give the same "This region has quota of 0 instances for your subscription. Try selecting different region or SKU." error.

mubranch commented 1 year ago

Confirmed "appsvc_linux_centralus" is showing again in the portal JSON and I receive the same quota error in VSCode. So in all failure instances (6 repros since Tues), app service was targeting central us.

Additionally, I live in Denver, Colorado if that is relevant.

charris-msft commented 1 year ago

Since it's possible that any Azure subscription could exceed its quota for a given resource in a particular region, it would be ideal to pre-check whether the provisioning will succeed (as much as possible, but at least a capacity check) and then change to another region if failure is certain.

Alternatively, the extension could try to provision in the default region, catch the failure, and then try another region while cleaning up unneeded resources in the default region (like the resource group).

alexweininger commented 1 year ago

Since it's possible that any Azure subscription could exceed its quota for a given resource in a particular region, it would be ideal to pre-check whether the provisioning will succeed (as much as possible, but at least a capacity check) and then change to another region if failure is certain.

As far as we know, there is no way to do this sort of advanced provision checking.

Alternatively, the extension could try to provision in the default region, catch the failure, and then try another region while cleaning up unneeded resources in the default region (like the resource group).

It will be difficult for us to know just based on the error message that changing the region will work any better. Plus, we'd have to ask for explicit consent before doing so.

An item that's been in our backlog for a while is "easily retry operations", which would especially when the error message is detailed. The error message can guide users to retry the operation with a different region. I also think simply showing a summary before starting the operation which allows for changing any variable (region, names, etc.) would be helpful here. Since even if a user knows that they need to change the region, they might not know how since our default create web app flow does not allow selecting region for the sake of simplicity.

charris-msft commented 1 year ago

@alexweininger - I still need to test this, but a friend ;) shared this approach with me for checking capacity using the Azure SDK.

To check the available capacity of App Service in the CentralUS region using the Azure SDK, you can follow these steps:

  1. Install the Azure SDK for your preferred programming language. Here, I'll use Python as an example. Install the Azure SDK for Python with the following command:
pip install azure-mgmt-resource
pip install azure-mgmt-web
  1. Set up authentication by creating a service principal or using the Azure CLI. To create a service principal, follow the instructions in the official Azure documentation.

  2. Once you have the service principal, export the following environment variables with the appropriate values:

export AZURE_SUBSCRIPTION_ID=<your_subscription_id>
export AZURE_CLIENT_ID=<your_client_id>
export AZURE_CLIENT_SECRET=<your_client_secret>
export AZURE_TENANT_ID=<your_tenant_id>
  1. Use the Azure SDK to check the available capacity of App Service in the CentralUS region:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.web import WebSiteManagementClient
import os

# Authenticate using the service principal
credentials = ServicePrincipalCredentials(
    client_id=os.environ["AZURE_CLIENT_ID"],
    secret=os.environ["AZURE_CLIENT_SECRET"],
    tenant=os.environ["AZURE_TENANT_ID"]
)

# Initialize the WebSiteManagementClient
web_client = WebSiteManagementClient(credentials, os.environ["AZURE_SUBSCRIPTION_ID"])

# Define the region and resource group name
location = "CentralUS"
resource_group_name = "<your_resource_group_name>"

# Get available app service plans
app_service_plans = web_client.app_service_plans.list_by_resource_group(resource_group_name)

# Calculate available capacity
total_capacity = 0
for plan in app_service_plans:
    if plan.location.lower() == location.lower():
        total_capacity += plan.number_of_workers

print(f"Available capacity in {location}: {total_capacity}")

Replace <your_resource_group_name> with the name of your resource group. This script calculates the total number of workers across all App Service plans in the specified region and resource group.

alexweininger commented 1 year ago

😄 with a few tweaks the script you provided gets the total number of App Service Plans that are in the Central US region. Unfortunately having the total number doesn't help us since we have no way of getting the limit.

alexweininger commented 1 year ago

Also, just to follow up on this issue. The service issue that caused the original issue has been resolved and the issue no longer reproduces.

salagger07 commented 1 year ago

Hi,

I receive this error when trying to run a test web app through Azure CLI.

scott [ ~ ]$ az webapp up --os Linux --location centralus --sku F1 --name educationapp-$RANDOM The webapp 'educationapp-620' doesn't exist Creating Resource group 'salagger_rg_0568' ... Resource group creation complete Creating AppServicePlan 'salagger_asp_3612' ... This region has quota of 0 instances for your subscription. Try selecting different region or SKU.

The location is 'centralus'.

Thanks.

alexweininger commented 1 year ago

I receive this error when trying to run a test web app through Azure CLI.

@salagger07, retrying the operation should fix the issue. Also, this repository is for the App Service VS Code extension, not the Azure CLI.

If you need additional help, file a new issue on the Azure CLI repository https://github.com/Azure/azure-cli

solidcitizen commented 1 year ago

It is still not working for the VS Code extension for the 'quick start deploy a python app' scenario. When doing so the Azure App Service log shows "Creating app service plan "appsvc_linux_centralus_basic"...and then "Error: This region has quota of 0 instances for your subscription.". However I did get through the instructions using CLI, and the "Create a new web app...(Advanced)" got me my new web app, as well...@mubranch thank for the input!

Smith-Steve commented 8 months ago

I have tried this in 3 different regions now and they have all failed. There is something wrong with this and it needs to be fixed. It would also be really helpful if the people from Microsoft didn't keep coming back to us and saying, "Well did you do this?", "Did you try that?" This is a 101 thing that Micrsoft should take care of; let's not pass the work off to others here.

nturinski commented 8 months ago

@Smith-Steve We totally agree about how frustrating this is and that it should be handled by Microsoft, not the customer. Unfortunately, we're only the extension tooling-- the only way for us to truly fix this is for the service team to provide an API for us to return a user's quota before we initiate the create. As it is, we don't find out about the error until the create fails.

Maybe one way that we can mitigate this for our users is to improve our error handling and to retry the create with a different location without having to go through all of the prompts again. Either the user can select a new location or we can automatically attempt another location and inform the user why the resource wasn't created in the location that they selected.

chriscarrollsmith commented 2 months ago

Can confirm this issue still occurs. It seems to be a limit imposed by Microsoft to prevent excessive tutorial usage from overloading their servers. Not an issue that can be addressed at the tooling level, alas.