Automate creation of Web App in Azure

In previous post Automate App Service Plan, I showed code snippet for automation of App Service Plan. Now that we have the plan, next step will be to add a Web App service to it. Following code snippet show automation of Web App service using Azure Sdk.

static void Main(string[] args)
            Console.WriteLine("Cloud Robot - Start");

            var prinicipalCredentials = SdkContext.AzureCredentialsFactory.FromFile("./");
            var azureInstance = Azure.Configure()
            var rgName = "my-rg";
            var rgLocation = "eastus";

            var rg = azureInstance.ResourceGroups.Define(rgName).WithRegion(rgLocation).Create();
            Console.WriteLine($"Resource group {rg.Name} created in region {rg.RegionName}");

            var appServicePlan = "my-webtest1-plan";
            var servicePlan = Task.Run(async () => await azureInstance.AppServices.AppServicePlans

            Console.WriteLine($"App Service Plan {servicePlan.Name} created in {servicePlan.Region}");

                var webApp = Task.Run(async () => await azureInstance.WebApps
                 ($"Web app {webApp.Name} create for {webApp.NetFrameworkVersion} in region {webApp.Region}");
            catch(Exception ex)

            Console.WriteLine("Cloud Robot - End");

There is one difference between code from previous code. I have changed the App Service Plan from Free Tier to Standard Tier. When you are selecting a tier for any type of Azure resource, it is important that you understand limitation of that tier. You may have some specific requirements for application that you want to deploy. If you choose a wrong tier then either the automation code will fail or you will end up with a resource that will not work for you. You will have to go back and delete that resource and probably App Service Plan as well to recreate resources. E.g. Free tier for Web App does not allow running on 64bit architecture. When I run the above code with Free tier App Service Plan, I will end up with an exception saying that there is a conflict. I had the following exception.

"Code":"Conflict","Message":"There was a conflict. 64 Bit worker processes cannot be used for the site as the plan does not allow it. For more information on pricing and features, please see: "

In case of conflict, Azure chose best possible options and created the App Service. But I had to go back and delete it. So, make sure that when you write automation code, you choose right set of options.




9.3 °C / 48.7 °F

weather conditions Clear

Monthly Posts

Blog Tags