Scaling Azure Websites

Can I scale azure web / api apps using Azure Management Libraries? Basically I want to implement scaling applications and throttling processing applications. Hence, I need to scale the web app and api apps through C # code. Any pointers to any suitable ReST library / API?

With the answer mentioned below, I understand how to update the APP service plan to scale down, however, I cannot find the webHostingPlanName for my APP service. I tried with the below code and the hosting plan is always null.

        var regionName = "myregion";

        var credentials = GetCredentials();

        var websiteManagementClient = CloudContext.Clients.CreateWebSiteManagementClient(credentials);

        var webSpaces = websiteManagementClient.WebSpaces.List();
        var webSpace = webSpaces.FirstOrDefault(x => x.GeoRegion == regionName);
        if (webSpace == null)
        {
            throw new Exception(string.Format("No webspace for region {0} found", regionName));
        }

        var webHostingPlans = websiteManagementClient.WebHostingPlans.List(webSpace.Name);
        var webHostingPlan = webHostingPlans.FirstOrDefault();// this is null always, I know an APP service exists in this region

      

0


source to share


1 answer


Yes, we can use the Microsoft.WindowsAzure.Management.Websites library to scale up and down web applications. Using a method WebSiteManagementClient.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters)

to implement it.

I made a demo for this. Below are my steps:

1.Install Microsoft.WindowsAzure.Management.WebSites so we can get it from ...

2. Create a WebsiteManagementClient object .

I used a certificate to create a websitemagement client.

  • Create a certificate using makecert.exe, which is under the VS folder after installing VS.

    makecert -sky exchange -r -n "CN=[CertificateName]" -pe -a sha1 -len 2048 -ss My "[CertificateName].cer
    
          

enter image description here

  • Download. Certify the file to the Azure portal, then get a fingerprint


enter image description here 3. Using Code to Create the WebsiteManagementClient Object

          public static X509Certificate2 GetCert(string thumbprint)
    {

        X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
        certStore.Open(OpenFlags.ReadOnly);
   X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
        if (certCollection.Count <= 0) return null;
        X509Certificate2 cert = certCollection[0];
        return cert;
    }

      

var cert = GetCert(string thumbprint) var subscriptionId ="Your subscriptionId" var webSiteManagementClient = new WebSiteManagementClient(new CertificateCloudCredentials(subscriptionId, cert));

4.Create the parameters WebHostingPlanUpdateParameters

var webHostingPlanUpdateParameters = new WebHostingPlanUpdateParameters
                {
                    NumberOfWorkers = 1, //the number of the instances
                    SKU = SkuOptions.Standard, 
                    WorkerSize = WorkerSizeOptions.Small
                };

      

5.Remove WebHostingPlans with code

client.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters);

      

Note. If you try to run a project on Azure. Please refer to Using Certificates in Azure Websites Apps . Adding application settings named WEBSITE_LOAD_CERTIFICATES with its value set to the certificate thumbprint will make it available to your web application.

+1


source







All Articles