Using the Free or Basic plan for your Azure AppService plan is a good way to start and discover what Azure will be able to do for you.

But when you go in production, you might want to use a different pricing tier, just to be able to use some interesting features available in Azure (custom domain, a strongest machine, etc.)

This action is really easy to do via the portal thanks to the “Scale up (App Service plan)” feature:

But what if you want to do the same using some (C#) code? Yes, of course, there is a way to do it using Azure CLI but as a C# developer, let me try to do it that way 🙂

Actually, it’s a pretty straitforward operation that implies to use the Azure C# SDK. After being connected to your Azure subscription (using a Service Principal), you just need to find the reference of your AppService plan and call the WithPricingTier method:

var azureCredentials = new AzureCredentials(new ServicePrincipalLoginInformation
    ClientId = config["ClientId"],
    ClientSecret = config["ClientSecret"]
}, config["TenantId"], AzureEnvironment.AzureGlobalCloud);

var azure = Azure.Configure()

var servicePlan = await azure
    .GetByResourceGroupAsync("myresourcegroup", "donotpanic");

await servicePlan

The selectedPricingTier can be any of the fields of the dedicated PricingTier class:

Be aware that to have this working, your Service Principal object ust have the rights to access the resources in the dedicated resources group.

That way, you can use upscale (or downscale) your AppService plan in a programatic way (using an Azure function, using a WebJob, etc.)

Happy coding !

Streaming Kubernetes' logs using SignalR

Leave a Reply

Your email address will not be published. Required fields are marked *