Can I scale azure web apps/api apps using Azure Management libraries? I basically want to implement scaling up and down of web apps to handle throttling. Hence, I need to sc
Yes, We can use Microsoft.WindowsAzure.Management.Websites library to scale up and down of web apps.
Using method WebSiteManagementClient.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters)
to implement it.
I had done a demo to do this. The following are the my detail steps:
1.Install the Microsoft.WindowsAzure.Management.WebSites that we can get it from the link.
2.Create the WebsiteManagementClient object.
I used the cert to create the websitemagement client.
Create a cert with makecert.exe that is under the VS folder after install the VS.
makecert -sky exchange -r -n "CN=[CertificateName]" -pe -a sha1 -len 2048 -ss My "[CertificateName].cer
3. Using the code to generate 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.Construct the WebHostingPlanUpdateParameters
var webHostingPlanUpdateParameters = new WebHostingPlanUpdateParameters
{
NumberOfWorkers = 1, //the number of the instances
SKU = SkuOptions.Standard,
WorkerSize = WorkerSizeOptions.Small
};
5.Update the WebHostingPlans with code
client.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters);
Note: If you try to run the project on the Azure. Please refer to document Using Certificates in Azure Websites Applications. Adding an app setting named WEBSITE_LOAD_CERTIFICATES with its value set to the thumbprint of the certificate will make it accessible to your web application