Automatically pause/resume and scale up/down Azure Analysis Services using AzureRM.AnalysisServices

One of the big advantages of Azure Analysis Services is the ability to pause/resume and scale up/down as needed, this will allow you to pay only for what you use and greatly reduce costs.

Azure Analysis Services team released a PowerShell module “AzureRM.AnalysisServices” with cmdlets to manage your Azure Analysis Services resources and they could be more easy to use:

  • Get-AzureRmAnalysisServicesServer – To get your server metadata and current status
  • Suspend-AzureRmAnalysisServicesServer – To suspend a server
  • Resume-AzureRmAnalysisServicesServer – To Resume a server
  • Set-AzureRmAnalysisServicesServer – To update a server, ex: change the SKU

More details here.

But this is only effective if we somehow automate this operation, it’s not feasible if someone on the team or customer is actively pausing/resuming or scaling up/down the instance

With that in mind we build a very simple PowerShell script where you configure in which time and days the Azure AS should be on and on which SKU.

Download the full script here.

The script is configured by a JSON metadata:

image

The above metadata will configure Azure AS to:

Days

Hours

SKU

Mon-Fri

8 AM to 18 PM (peak hours)

S1

Mon-Fri

18 PM to 00 AM (off peak)

S0

Sat-Sun

8 AM to 00 AM

S0

Other

Other

Pause

The powershell script has the following parameters:

-resourceGroupName

The name of the Azure Resource Group your Azure AS server is deployed:

clip_image002[5]

-serverName

The name of the Azure AS Server:

clip_image004

-configStr

The JSON metadata config string

-azureProfilePath

(optional)

The path to an Azure profile stored locally using the “Save-AzureRmContext” cmdlet.

This is useful to test the script locally.

-azureRunAsConnectionName

(optional)

The name of Azure Connection if you want to run this script in a Azure Automation RunBook:

clip_image006

Probably most of you will want to run this script on an PowerShell Runbook in Azure Automation, learn how to setup the Azure Automation here.

Next you will need to register the module “AzureRM.AnalysServices” as an Asset of your automation account:

clip_image002[7]

After that just create a new PowerShell runbook:

clip_image004[4]

Paste the script and remember to set the parameter -azureRunAsConnectionName:

clip_image006[4]

Publish the script and create a schedule:

clip_image008

clip_image010

That’s it! You know have your Azure AS automatically pausing/resuming and scalling up/down using a configuration file you defined.

Now just lay back and measure the savings at the end of the month!

8 thoughts on “Automatically pause/resume and scale up/down Azure Analysis Services using AzureRM.AnalysisServices

      • JosVermeire says:

        Hi Rui,
        Thank you for the swift reply. I checked the documentation for getting the parameters for the Basic & development tier the ” The supported values are ‘S0’, ‘S1’, ‘S2’, ‘S4’ for the Standard tier; ‘B1’, ‘B2’ for the Basic tier and ‘D1’ for Development tier.” However when adjusting the sku parameter in the script I receive following error (same for B1 and D1).

        Logging in to Azure…
        Current Azure AS status: Succeeded
        Is in active hours
        Updating AAS server from S0 to B2
        Performing the operation “Update Analysis Services Server” on target “aasbmap”.
        Set-AzureRmAnalysisServicesServer : The new size is not available

        Don’t quite understand what goes wrong here…

        Like

  1. JosVermeire says:

    Ok, found it. Apparantly not an option to scale down service tiers:

    “Customers can change performance levels within a tier. For example, customers can move from an S2 to S4 seamlessly or vice-versa. Customers can also move from a lower tier to a higher tier but NOT vice-versa. For example, you can move from Basic to Standard tier or Developer to Basic tier, but you can’t move from a Standard to Basic tier or Basic to Developer tier.”

    Like

  2. Naveen says:

    Above code is working perfectly when I execute it through runbook. But while executing created runbook (with above code) in Logicapp, I am getting error: Invalid JSON primitive: 1,2,3,4,5]”……
    kindly help

    Like

Leave a comment