Home
%3CLINGO-SUB%20id%3D%22lingo-sub-369177%22%20slang%3D%22en-US%22%3EHow%20to%20auto-scale%20an%20Azure%20Database%20for%20MySQL%2FPostgreSQL%20instance%20with%20Azure%20run%20books%20and%20Python%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-369177%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Jan%2022%2C%202019%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20One%20of%20the%20many%20great%20features%20of%20Azure%20SQL%20Database%20is%20the%20ability%20to%20scale%20up%20or%20down%20depending%20on%20the%20amount%20of%20workload%20an%20instance%20is%20processing%2C%20which%20means%20there%20is%20greater%20control%20of%20the%20instance%20that%20can%20translate%20into%20greater%20cost%20savings.%20But%20what%20about%20those%20moments%20where%20the%20workload%20increases%20and%20we%20don't%20notice%20it%20until%20our%20instance%20is%20suffering%20from%20resource%20exhaustion%3F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20By%20leveraging%20the%20power%20of%20Azure%20run%20books%2C%20we%20can%20set%20up%20a%20simple%20script%20that%20auto-scales%20the%20instance%20and%20is%20fired%20by%20an%20alert%20configured%20to%20execute%20the%20run%20book%20when%20a%20certain%20metric%20happens%3B%20i.e.%20CPU%20usage%20goes%20above%2090%25.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20This%20quick%20tutorial%20explains%20how%20to%20set%20up%20the%20script%20that%20scales%20the%20instance%20in%20question.%20The%20following%20steps%20use%20PostgreSQL%20as%20example%2C%20but%20the%20same%20method%20can%20be%20used%20for%20Azure%20Database%20for%20MySQL.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%201.%20Create%20an%20Azure%20automation%20account.%20You%20can%20create%20one%20quickly%20by%20searching%20for%20automation%20on%20the%20Portal's%20search%20bar.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89102i2936E2D4E00525A1%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%202.%20We%20need%20to%20import%20several%20Python%202%20packages%20in%20order%20to%20have%20the%20correct%20libraries%20to%20set%20up%20the%20management%20of%20MySQL%2FPostgreSQL%20resources%20in%20Azure.%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EPlease%20make%20sure%20that%20Python%202.x%20is%20installed%20on%20your%20computer%20and%20pip%20is%20updated.%20Azure%20Automation%20works%20only%20with%20Python%202.x%20so%20these%20are%20the%20packages%20we%20need%20to%20gather%20beforehand.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EIf%20not%20using%20the%20newest%20version%20of%20pip%2C%20update%20it%20following%20%3CA%20href%3D%22https%3A%2F%2Fpip.pypa.io%2Fen%2Fstable%2Finstalling%2F%23upgrading-pip%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20this%20%3C%2FA%3E%20documentation.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EOpen%20a%20new%20cmd%20window%20and%20run%3A%20%3CBR%20%2F%3E%20pip%20download%20-d%20locationToDownloadThePackages%20azure-mgmt-rdbms%20%3CBR%20%2F%3E%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EThis%20will%20download%20(but%20not%20install)%20the%20required%20SDK%20and%20its%20dependencies%20in%20.WHL%20format.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EReturn%20to%20the%20Azure%20Portal%20and%20look%20for%20%3CSTRONG%3E%20Python%202%20packages%20%3C%2FSTRONG%3E%20which%20will%20be%20one%20of%20the%20blades%20for%20the%20automation%20account%3A%20%3CBR%20%2F%3E%3CUL%3E%0A%20%20%20%20%3C%2FUL%3E%3CBR%20%2F%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89103iEB1FE44CD4D29A54%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3ENext%2C%20we%20will%20import%20every%20file%20we%20downloaded%20with%20pip%20to%20this%20account%20by%20clicking%20%3CSTRONG%3E%20Add%20a%20Python%202%20package%20%3C%2FSTRONG%3E%20%2C%20browsing%20and%20uploading%20every%20.WHL%20file.%20The%20list%20will%20look%20something%20like%20this%3A%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89104i0E744FB97DE1BF90%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%203.%20Now%20we%20are%20ready%20to%20start%20the%20coding%20part%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3ENavigate%20to%20the%20%3CSTRONG%3E%20Runbooks%20%3C%2FSTRONG%3E%20blade%20and%20click%20%3CSTRONG%3E%20Create%20a%20runbook%3C%2FSTRONG%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89105i81687C9BB3705C27%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EEnter%20the%20requested%20details%20and%20after%20you%20create%20your%20runbook%2C%20click%20it%20and%20then%20click%20%3CSTRONG%3E%20Edit.%20%3C%2FSTRONG%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89106iF5C8DD6798836D77%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EOn%20another%20tab%2C%20open%20the%20Azure%20Portal%20and%20click%20the%20%3CSTRONG%3E%20Cloud%20Shell%20%3C%2FSTRONG%3E%20button%20to%20start%20a%20new%20bash%20session%2C%20we%20need%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpython%2Fazure%2Fpython-sdk-azure-authenticate%3Fview%3Dazure-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20create%20%3C%2FA%3E%20a%20service%20principal%20that%20will%20be%20allowed%20to%20manage%20the%20server.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89107iB7AD5962505C199F%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EWhen%20it%20loads%20(CLI%2C%20not%20PowerShell)%2C%20execute%20the%20following%20command%20to%20create%20a%20principal%3A%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20az%20ad%20sp%20create-for-rbac%20--name%20%22MY-PRINCIPAL-NAME%22%20--password%20%22STRONG-SECRET-PASSWORD%22%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EIt%20will%20take%20a%20while%20but%2C%20when%20it%20finishes%2C%20please%20make%20sure%20to%20note%20the%20Tenant%20ID%20and%20App%20ID.%20We%20will%20need%20those%20in%20the%20next%20steps.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%204.%20Now%20back%20to%20Step%203%2C%20when%20you%20click%20Edit%2C%20a%20new%20editor%20interface%20will%20open%20and%20the%20following%20code%20will%20go%20there.%20Please%20pay%20attention%20to%20the%20important%20parts%20you%20need%20to%20modify%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3ETenant%20ID%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EService%20Principal's%20Application%20ID%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EService%20Principal's%20password%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ESubscription%20ID%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EResource%20Group%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EName%20of%20the%20PostgreSQL%20instance%20to%20scale%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ESKU%3A%20the%20SKU%20is%20the%20most%20important%20part%20to%20define%2C%20as%20this%20will%20tell%20the%20instance%20to%20which%20tier%20scale%20up%20or%20down.%20Note%20that%20in%20the%20example%20below%20I%20used%20%3CSTRONG%3E%20B_Gen5_2%20%3C%2FSTRONG%3E%20%2C%20which%20means%20a%20Basic%20tier%2C%20Generation%205%20CPU%20with%202%20cores.%20To%20learn%20more%20about%20how%20you%20can%20mix%20and%20match%20these%20parameters%2C%20please%20refer%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fmt-mt%2Fpython%2Fapi%2Fazure-mgmt-rdbms%2Fazure.mgmt.rdbms.postgresql.models.sku(class)%3Fview%3Dazure-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20this%20documentation%20%3C%2FA%3E%20.%20You%20can%20use%20only%20the%20name%20(as%20in%20the%20example)%2C%20or%20use%20a%20mix%20of%20name%2C%20tier%2C%20capacity%2C%20size%20or%20family%20depending%20on%20your%20needs.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bsourcecode%20language%3D%22python%22%20collapse%3D%22false%22%5D%20%3CBR%20%2F%3E%20%22%22%22%20%3CBR%20%2F%3E%20Azure%20Automation%20documentation%20%3A%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fazure-automation-python-documentation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Faka.ms%2Fazure-automation-python-documentation%3C%2FA%3E%20%3CBR%20%2F%3E%20Azure%20Python%20SDK%20documentation%20%3A%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fazure-python-sdk%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Faka.ms%2Fazure-python-sdk%3C%2FA%3E%20%3CBR%20%2F%3E%20%22%22%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20import%20os%20%3CBR%20%2F%3E%20import%20sys%20%3CBR%20%2F%3E%20import%20adal%20%3CBR%20%2F%3E%20from%20azure.common.credentials%20import%20ServicePrincipalCredentials%20%3CBR%20%2F%3E%20from%20azure.mgmt.rdbms.postgresql%20import%20PostgreSQLManagementClient%20%3CBR%20%2F%3E%20from%20azure.mgmt.rdbms.postgresql.models%20import%20ServerUpdateParameters%2C%20Sku%20%3CBR%20%2F%3E%20import%20azure.mgmt.resource%20%3CBR%20%2F%3E%20import%20automationassets%20%3CBR%20%2F%3E%20import%20msrest%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20Tenant%20ID%20for%20your%20Azure%20Subscription%20%3CBR%20%2F%3E%20TENANT_ID%20%3D%20'xxxxxxxx-xxxxxx-xxxxx'%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20Your%20Service%20Principal%20App%20ID%20%3CBR%20%2F%3E%20CLIENT%20%3D%20'xxxxxx-xxxxx-xxxxxx'%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20Your%20Service%20Principal%20Password%20%3CBR%20%2F%3E%20KEY%20%3D%20'xxxxxxxxxx'%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20credentials%20%3D%20ServicePrincipalCredentials(%20%3CBR%20%2F%3E%20client_id%20%3D%20CLIENT%2C%20%3CBR%20%2F%3E%20secret%20%3D%20KEY%2C%20%3CBR%20%2F%3E%20tenant%20%3D%20TENANT_ID%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23Subscription%2C%20Resource%20Group%20and%20name%20of%20the%20PostgreSQL%20instance%20we%20will%20auto-scale%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20SUBSCRIPTION_ID%20%3D%20%22xxxxxxxx-xxxxxxx-xxxxxx%22%20%3CBR%20%2F%3E%20RESOURCE_GROUP%20%3D%20%22xxxxxxxxxxxx%22%20%3CBR%20%2F%3E%20POSTGRES_SERVER%20%3D%20%22xxxxxxxxxxxx%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20client%20%3D%20PostgreSQLManagementClient(credentials%2C%20SUBSCRIPTION_ID)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20server_creation_poller%20%3D%20client.servers.update(%20%3CBR%20%2F%3E%20resource_group_name%20%3D%20RESOURCE_GROUP%2C%20%3CBR%20%2F%3E%20server_name%20%3D%20POSTGRES_SERVER%2C%20%3CBR%20%2F%3E%20parameters%20%3D%20ServerUpdateParameters(%20%3CBR%20%2F%3E%20sku%20%3D%20Sku(%20%3CBR%20%2F%3E%20name%20%3D%20%22B_Gen5_2%22%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20srv%20%3D%20server_creation_poller.result()%20%3CBR%20%2F%3E%20%5B%2Fsourcecode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%205.%20When%20the%20required%20changes%20to%20the%20code%20are%20done%2C%20we%20are%20ready%20to%20test!%20%3CBR%20%2F%3E%206.%20Click%20on%20%3CSTRONG%3E%20Test%20Pane%20%3C%2FSTRONG%3E%20and%20then%20%3CSTRONG%3E%20Run.%20%3CBR%20%2F%3E%20%3C%2FSTRONG%3E%207.%20The%20run%20book%20will%20start%20to%20execute%20and%20it%20will%20show%20complete%20when%20done.%20By%20this%20time%20the%20instance%20will%20start%20to%20scale%20up%20or%20down%20and%20you%20will%20soon%20see%20the%20changes%20reflected%20in%20the%20Overview%20blade%20of%20the%20PostgreSQL%20instance.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20After%20confirming%20that%20the%20run%20book%20correctly%20scaled%20the%20Azure%20Database%20for%20PostgreSQL%20instance%2C%20you%20can%20then%20follow%20the%20next%20tutorial%20to%20fire%20this%20run%20book%20from%20an%20Azure%20alert.%20This%20way%20if%20the%20instance%20suddenly%20encounters%20an%20increase%20in%20workload%2C%20the%20run%20book%20will%20automatically%20run%20and%20scale%20accordingly.%20%3CBR%20%2F%3E%3CH3%20id%3D%22use-an-alert-to-trigger-an-azure-automation-runbook%22%20id%3D%22toc-hId-1482507226%22%20id%3D%22toc-hId-1505479769%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fautomation%2Fautomation-create-alert-triggered-runbook%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Use%20an%20alert%20to%20trigger%20an%20Azure%20Automation%20runbook%20%3C%2FA%3E%3C%2FH3%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-369177%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jan%2022%2C%202019%20One%20of%20the%20many%20great%20features%20of%20Azure%20SQL%20Database%20is%20the%20ability%20to%20scale%20up%20or%20down%20depending%20on%20the%20amount%20of%20workload%20an%20instance%20is%20processing%2C%20which%20means%20there%20is%20greater%20control%20of%20the%20instance%20that%20can%20translate%20into%20greater%20cost%20savings.%3C%2FLINGO-TEASER%3E
Microsoft
First published on MSDN on Jan 22, 2019
One of the many great features of Azure SQL Database is the ability to scale up or down depending on the amount of workload an instance is processing, which means there is greater control of the instance that can translate into greater cost savings. But what about those moments where the workload increases and we don't notice it until our instance is suffering from resource exhaustion?

By leveraging the power of Azure run books, we can set up a simple script that auto-scales the instance and is fired by an alert configured to execute the run book when a certain metric happens; i.e. CPU usage goes above 90%.

This quick tutorial explains how to set up the script that scales the instance in question. The following steps use PostgreSQL as example, but the same method can be used for Azure Database for MySQL.

1. Create an Azure automation account. You can create one quickly by searching for automation on the Portal's search bar.







2. We need to import several Python 2 packages in order to have the correct libraries to set up the management of MySQL/PostgreSQL resources in Azure.

  • Please make sure that Python 2.x is installed on your computer and pip is updated. Azure Automation works only with Python 2.x so these are the packages we need to gather beforehand.

  • If not using the newest version of pip, update it following this documentation.

  • Open a new cmd window and run:
    pip download -d locationToDownloadThePackages azure-mgmt-rdbms

  • This will download (but not install) the required SDK and its dependencies in .WHL format.

  • Return to the Azure Portal and look for Python 2 packages which will be one of the blades for the automation account:









  • Next, we will import every file we downloaded with pip to this account by clicking Add a Python 2 package , browsing and uploading every .WHL file. The list will look something like this:








3. Now we are ready to start the coding part:

  • Navigate to the Runbooks blade and click Create a runbook








  • Enter the requested details and after you create your runbook, click it and then click Edit.








  • On another tab, open the Azure Portal and click the Cloud Shell button to start a new bash session, we need to create a service principal that will be allowed to manage the server.








  • When it loads (CLI, not PowerShell), execute the following command to create a principal:


az ad sp create-for-rbac --name "MY-PRINCIPAL-NAME" --password "STRONG-SECRET-PASSWORD"

  • It will take a while but, when it finishes, please make sure to note the Tenant ID and App ID. We will need those in the next steps.


4. Now back to Step 3, when you click Edit, a new editor interface will open and the following code will go there. Please pay attention to the important parts you need to modify:

  • Tenant ID

  • Service Principal's Application ID

  • Service Principal's password

  • Subscription ID

  • Resource Group

  • Name of the PostgreSQL instance to scale

  • SKU: the SKU is the most important part to define, as this will tell the instance to which tier scale up or down. Note that in the example below I used B_Gen5_2 , which means a Basic tier, Generation 5 CPU with 2 cores. To learn more about how you can mix and match these parameters, please refer to this documentation . You can use only the name (as in the example), or use a mix of name, tier, capacity, size or family depending on your needs.



[sourcecode language="python" collapse="false"]
"""
Azure Automation documentation : https://aka.ms/azure-automation-python-documentation
Azure Python SDK documentation : https://aka.ms/azure-python-sdk
"""

import os
import sys
import adal
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient
from azure.mgmt.rdbms.postgresql.models import ServerUpdateParameters, Sku
import azure.mgmt.resource
import automationassets
import msrest

# Tenant ID for your Azure Subscription
TENANT_ID = 'xxxxxxxx-xxxxxx-xxxxx'

# Your Service Principal App ID
CLIENT = 'xxxxxx-xxxxx-xxxxxx'

# Your Service Principal Password
KEY = 'xxxxxxxxxx'

credentials = ServicePrincipalCredentials(
client_id = CLIENT,
secret = KEY,
tenant = TENANT_ID
)

#Subscription, Resource Group and name of the PostgreSQL instance we will auto-scale

SUBSCRIPTION_ID = "xxxxxxxx-xxxxxxx-xxxxxx"
RESOURCE_GROUP = "xxxxxxxxxxxx"
POSTGRES_SERVER = "xxxxxxxxxxxx"

client = PostgreSQLManagementClient(credentials, SUBSCRIPTION_ID)

server_creation_poller = client.servers.update(
resource_group_name = RESOURCE_GROUP,
server_name = POSTGRES_SERVER,
parameters = ServerUpdateParameters(
sku = Sku(
name = "B_Gen5_2"
)
)
)

srv = server_creation_poller.result()
[/sourcecode]

5. When the required changes to the code are done, we are ready to test!
6. Click on Test Pane and then Run.
7. The run book will start to execute and it will show complete when done. By this time the instance will start to scale up or down and you will soon see the changes reflected in the Overview blade of the PostgreSQL instance.

After confirming that the run book correctly scaled the Azure Database for PostgreSQL instance, you can then follow the next tutorial to fire this run book from an Azure alert. This way if the instance suddenly encounters an increase in workload, the run book will automatically run and scale accordingly.

Use an alert to trigger an Azure Automation runbook