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("./azureauth.info"); var azureInstance = Azure.Configure() .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) .Authenticate(prinicipalCredentials) .WithDefaultSubscription(); 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 .Define(appServicePlan) .WithRegion(rgLocation) .WithExistingResourceGroup(rgName) .WithPricingTier(PricingTier.StandardS1) .WithOperatingSystem(Microsoft.Azure.Management.AppService.Fluent.OperatingSystem.Windows) .CreateAsync()).Result; Console.WriteLine($"App Service Plan {servicePlan.Name} created in {servicePlan.Region}"); try { var webApp = Task.Run(async () => await azureInstance.WebApps .Define("my-webapp1-qa") .WithExistingWindowsPlan(servicePlan) .WithExistingResourceGroup(rg) .WithHttpsOnly(true) .WithNetFrameworkVersion(NetFrameworkVersion.V4_6) .WithWebAppAlwaysOn(true) .WithWebSocketsEnabled(true) .WithPlatformArchitecture(PlatformArchitecture.X64) .WithManagedPipelineMode(ManagedPipelineMode.Integrated) .CreateAsync()).Result; Console.WriteLine ($"Web app {webApp.Name} create for {webApp.NetFrameworkVersion} in region {webApp.Region}"); } catch(Exception ex) { Console.WriteLine($"{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: https://aka.ms/appservicepricingdetails "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.
Deploying a web application under DNN
How to automate creation of App Service Plan in Azure using Azure SDK
How to Handle HTML Events in Typescript
Fix error CS4034: The await operator can only be used within an async lambda expression
How to Automatically unzip compressed response with .Net Core HttpClient
Alert and Confirm pop up using BootBox in AngularJS
AngularJS Grouped Bar Chart and Line Chart using D3
How to lock and unlock account in Asp.Net Identity provider
2021 © Byteblocks, ALL Rights Reserved. Privacy Policy | Terms of Use