0

How can one deploy a Powershell api to Azure Functions. The official documentation only talks about deploying a JavaScript function.

One doesn't get an option to select 'Powershell' during language selection while creating a 'Project' thru the Azure Functions extension.

This is a default Powershell api when deployed from the Azure Portal.

# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name
# GET method: each querystring parameter is its own variable
if ($req_query_name) 
  {$name = $req_query_name}
Out-File -Encoding Ascii -FilePath $res -inputObject "Hello $name"

I tried to deploy the below code directly using the VSC Azure Function's 'Deploy' button. But I get the below error.

Unable to write Workspace settings because no workspace is opened. Please open a workspace first and try again

1 Answer 1

1

Unable to write Workspace settings because no workspace is opened. Please open a workspace first and try again.

In VSCode, we have to open a folder or create a function project first, or the file to hold Workspace settings can't be created, and we will get the error when trying to modify Workspace settings like runtime, language and template filter.

Detailed Steps of Developing Azure Function in VSCode(references from official tutorial):

Tips

  1. Languages like Powershell are experimental so don't use them in production. Powershell/Python support on 2.x runtime are also in progress.

  2. Install functions core tools(cli) to debug functions locally.

    1.x for OS Windows .NET Framework, 2.x for cross platform .NET Core.

Install Azure Function Extension

Input vscode:extension/ms-azuretools.vscode-azurefunctions in brower, it will open VScode and install extensions.

Create a Function project

  1. Create an empty folder in File explorer ; say MyFunctionApp

  2. Log into Azure Account.

  3. In Azure Function Extension, Click Create New Project and point to created folder MyFunctionApp.

  4. Select language JavaScript

Create a Function

  1. Click Create Function and browser MyFunctionApp folder. Then you may see the dropdown menu as below. Project runtime is automatically set based on cli installed.

    enter image description here

  2. Click Change template filter and change it to All so that we can see all templates available.

  3. Click Change project language to select experiment language like Powershell.

  4. Follow the rest prompt to create an Http trigger.

Debug or run function locally

For c#, javascript and java, feel free to F5.

To run function in experimental language locally, open terminal in VSCode(Ctrl+`) and run func host start, no debug support so don't use F5.

To test a httptrigger, suffix function url with ?name=World! to get Hello World response from your URL.

Deploy

Click Deploy to Function App button and follow the prompt.

Sign up to request clarification or add additional context in comments.

10 Comments

@AyanMullick Yes, this Node.js and npm requirement is used to install Azure function core tools to run functions locally. If you only want to deploy and test online, no need to install node related resources.
@AyanMullick You are trying to run function cli locally, it requires installing nodejs and npm on Windows. And $ is an shell signal on OS like Mac, just run func if you have installed function core tools.
@AyanMullick Have updated my answer with details, see whether it's useful for you.
Steps taken 1. Create Function 2. Select a blank folder 3. It prompts for project initialization. I say Yes. 4. Select JavaScript for language selection 5. Change project runtime and ~1(Approved for Production use) Screen 6. And it gives an error Unable to write Workspace settings because no workspace is opened. Please open a workspace first and try again Screen
@AyanMullick Got it. You should open a folder first in VSCode or create a function project first, or the file to hold Workspace settings can't be created, and you will get the error when trying to modify runtime.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.