Automating ML compute instance via script

Helan Nivas 0 Reputation points
2024-04-18T15:02:53.3066667+00:00

Hello,

We do have lot of ML compute instance running and every month we need to delete it and re-create it with same config. we are planning to create a script to perform this activity and then will schedule it once a month.

what's the best way to perform this activity in azure? Azure CLI or PowerShell ? Please let me know.

Thanks

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,959 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Burlachenko 990 Reputation points
    2024-04-18T15:40:52.08+00:00

    Once you have this script, you can schedule it to run once a month using a task scheduler like Windows Task Scheduler or Azure Automation :))))

    
    # Import the module
    Import-Module Az
    
    # Connect to your Azure account
    Connect-AzAccount
    
    # Get the ML compute instance
    $computeInstance = Get-AzResource -ResourceGroupName "<ResourceGroupName>" -ResourceType "Microsoft.MachineLearningServices/workspaces/computes" -ResourceName "<WorkspaceName>/<ComputeName>"
    
    # Delete the ML compute instance
    Remove-AzResource -ResourceId $computeInstance.ResourceId -Force
    
    # Recreate the ML compute instance with the same configuration
    New-AzResource -ResourceGroupName "<ResourceGroupName>" -ResourceType "Microsoft.MachineLearningServices/workspaces/computes" -ResourceName "<WorkspaceName>/<ComputeName>" -Properties $computeInstance.Properties -Force
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.