-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AzureFunction: The term 'New-AzureStorageContext' is not recognized #1426
Comments
Assuming that your Function is using the default installed Azure PowerShell version 1.4, could you kindly add the following to the beginning of your PowerShell run.ps1 script, and see if the issue goes away? Import-Module "D:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1" -Global |
The Import-Module fails. Error in dev-console (from try/catch)
But the error for Login-AzureRmAccount has changed:
|
Seems like there is something not quite right in the environment that your Function App landed on. I apologize for the churn, but could you also add the following to your script? Import-Module "D:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Profile\AzureRM.Profile.psd1" -Global; I'll be monitoring this thread so let me know if you see any more errors. |
FYI, to disover the path to any required Azure PowerShell *.psd1 files, you may use the Kudu PowerShell console to navigate the directory structure of the installed Azure PowerShell modules directory. Here are the steps:
If you see anymore errors about missing [xxxxxxx].psd1 files, locate the absolute path for those files and add them to your script. For certain cmdlets, the order that they are imported matters as well. |
All three Import-Module fails with the same System.ArgumentOutOfRangeException error. Now the function has this issue as I did not restart the function AppSerivce. That's why I was able to play with it and followed your recommendations: modified the code online from Portal UI and did HTTP call to see the result. |
Could you kindly share your Function App name, either directly or indirectly? Also, I will need to know the name of the Function that is failing. This will help me investigate further. Thanks! |
@knikol, I was not able to reproduce the error with my own setup. I created a HTTP trigger that reads from a config.json file and uses the Login-AzureRmAccount cmdlet. I triggered the Function many times and did not see errors. I will need to see this repro in your environment. Is it possible for me to run your RetriveVMStatus Function or could you create another Function that is very similar to RetrieveVMStatus but only have the code segment that uses the Login-AzureRmAccount and give me permission to run the Function? |
@tohling , please, try to send POST request to the url with JSON body:
|
@knikol, yes I can see the 500 error in the request response. Unfortunately, since I cannot repro this elsewhere, I basically need permission from you to troubleshoot from within your Function App. Would you agree to me creating another Function in this Function App that only calls the Login-AzureRmAccount cmdlet? I would like to isolate the code-path as much as possible. |
Yes, go ahead please. |
@knikol, I have created a new Function named TestFunction within your Function App. I was able to reproduce the error in that state. But I noticed that when I restarted the Function App, the error went away, both for TestFunction as well as RetrieveVMStatus. My suspicion is that your m360nebula-mno547ob4xooc Function App process may have been in a bad state that manifested itself into this error. I am re-reading your first post on this thread. I have some follow-up questions:
|
|
@knikol - Thank you for your quick response. I gather that you are using an App Service Plan and not the Consumption Plan since you are able to execute the long running operations. Unfortunately, at this experimental stage, we have not tested the impact of long running operations for the Azure PowerShell scenarios. One possibility is to start the long running script using the Start-Job cmdlet. That long running script can write to a storage queue when it is done. You can then have a Queue-Triggered Function notify you when the message is detected in the queue. If this becomes too cumbersome for your workflow, we highly recommend using Azure Automation. |
FYI - I see this was added to the May 2017 Milestone, great. I am adding to this post as we also have a number of PowerShell Functions added in our production environment with some intermittent issues. We deployed about 2 weeks ago in production with NO issues but in the last few days we have had many issues. Our functions simply need to Login to Azure and execute a single command. We are using functions as a scheduler. When everything is working, functions take apx. 3-5 Seconds to complete. However, like above there seem to be some instances of error/inconsistency depending on the environment the Function App landed on: Scirpt:
1: From Cold Start - my functions often time out / fail when using Add-AzureRmAccount - Second run is fine - but this is troublesome from a monitoring / alerting perspective.
Like you mentioned above, a stop/start of the function will pretty much always fix the issue, but these functions need to be running on schedule and a failure that requires a person to login and restart the function app causes customer impact / service outage. I see you made a reference to try importing the Azure Module manually using the direct path - this does work fine in our DEV environment so I will likely migrate this step as a "just in case" - Thanks for the kudu debug steps as well. I will run some more tests and keep you posted. UPDATE: Hello after fighting lots of intermittent issues today, this seem to have done the trick!
also apologies that I ended up here on the "Azure-Webjobs-SDK-Script" issues list, there are a few responces on this issue over at the Azure/Azure-Functions repo: I am going to continue to monitor and blog on things to watch out for when using Powershell Azure Functions and the AzureRM Modules |
Repro steps
Issue occurs randomly: no real steps to reproduce.
Expected behavior
No errors occur, HTTP call succeeds
Actual behavior
In Azure Portal dev-console:
HTTP response:
Known workarounds
Issue is resolved for a while by restarting of Azure Function (AppService) from Azure Portal UI
Related information
The text was updated successfully, but these errors were encountered: