I would like to receive a HTTP post request from a web application, and then run a command on the VM (like I would when I SSH into the VM) and return the output. Is this possible using a runbook or any other Azure services?
I would like to receive a HTTP post request from a web application, and then run a command on the VM (like I would when I SSH into the VM) and return the output. Is this possible using a runbook or any other Azure services?
Hi @np-0814,
If it's Azure VM then you could start it using Az PS Cmdlet Start-AzVM and then you can have commands stored as script in a storage blob and run those commands in the VM using Az PS cmdlet Invoke-AzVMRunCommand. For more information w.r.t it or for illustration, please refer this thread.
Let me know if you have any further queries around it. Also, If you have queries on how to implement receiving a HTTP post request from a web application, etc. I believe you would have to use curl if it has to be from the script that is stored in storage blob / use Invoke-RestMethod if it has to be from runbook itself. To provide exact implementation assistance, please provide more context like your exact use case / scenario / flow that's intended.
Thank you so much for your detailed answer -- it's clarified many things for me and I am able to accomplish all the steps in the attached thread. I'm just still unsure about how to access the files in my VM. My workflow now is:
Receive a webhook
Initiate this runbook
Run a shell script that is on my Linux VM, which will go through and run several python scripts on the VM.
Send a file that's saved on the VM (as a result of running the python scripts) to the web application that sent the webhook. (I'm not sure if this step is feasible?)
From what I'm working with so far I don't seem to be able to access the files in my VM through the script in my container/blob storage.
Hi @np-0814,
We can access the files in VM as well but to implement it we would have to save your script (that's saved in container/blob storage in above workflow) directly in the VM and then call that script using your runbook which has Invoke-AzVMRunCommand cmdlet. For the sample runbook, please refer this / this threads.
Make sure your script has those lines of code to remotely send the result files of python scripts to web app without any access or permission issue.
Hi @np-0814,
To check feasibility to send the result files of python scripts to web app and to try providing implementation assistance in that end, please provide more context like your exact use case / scenario / flow that's intended i.e., what is the kind of your web app? Is it hosted on Azure Web App / App Service / another VM / on-premise instance?, etc.
13 people are following this question.