How to run Azure VM using Azure Powershell Function

Nandika Taneja 21 Reputation points
2022-01-08T14:09:42.707+00:00

I am trying to create an azure function which can be called over http to start a VM in azure in the same resource group.

i am using azure for students subscription
For this i followed these steps:
1)Created a function app based on windows powershell with mode=consumption
2)Included Az and Az.compute as dependencies in the requirements.
3)set function timeout to 5 mins in host file
4)used below command in function code to start my VM
Start-AzVM -ResourceGroupName "xxxx" -Name "xxxxx"
5)if i test my functio without above start command it works without error but with this command it gives the attached error. i am trying this for more than one hour but getting the same error
163374-azurefunctionerrorpng.png

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,037 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,481 Reputation points
    2022-01-10T09:33:33.253+00:00

    @Nandika Taneja ,

    Thanks for reaching out to Q&A.

    Here are some steps to troubleshoot/mitigate 503 errors in Functions:

    1. Launch the hostname url (appname.azurewebsites.net) and check if the app is running or not.
    2. If the app isnt running, try restarting the app.
    3. Open the Diagnose and solve problems blade and run the "Function app down or reporting errors" detector. It should give you some insights.
    4. Sometimes we see 503 error when there some issues with the powershell script.

    In order to manage resources in your subscription from the Azure functions, you will have to enable system assigned MSI for the function and provide contributor access to the Function app's MSI.

    If you are going to use function app to just start/stop VM, we already have a feature for it : https://learn.microsoft.com/en-us/azure/azure-functions/start-stop-vms/overview
    Please note that, this feature is still in preview.

    I hope this helps!

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


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.