I want to create a very simple serverless function in Java for my web app. But I am having no success adding it to my function app.
Unfortunately most tutorials on the web and youtube seem to be out of date. The most recent videos show that there is a Function f(x) option in the function section. But at the moment this option seems to be not visible to me.
See screenshot :
As I think I understand you have to go to the “Create in Azure portal” button in functions tab
So I click on the button "Create in Azure Portal"
- Select "Choose any editor + core tools"
- Open the cloud shell
- Run “func init” (I am not sure if this was correct. I think I needed to create a folder first. Now all these files are in the base directory)
- Run “func new”. (Selecting on HTTP Request)
- Then I run “func azure functionapp publish oliverwatkinsserverlessfunction”
I then get this error :
oliver [ ~/src ]$ func azure functionapp publish oliverwatkinsservlessfunction
Your Azure Function App has 'FUNCTIONS_WORKER_RUNTIME' set to 'java' while your local project is set to 'node'.
You can pass --force to update your Azure app with 'node' as a 'FUNCTIONS_WORKER_RUNTIME'
And I don't see any new function.
As I understand my function app is Java so I am not sure why it thinks it is a node application
It looks like
FUNCTIONS_WORKER_RUNTIME: java
is not supported by core tools while creating the function usingfunc init
command. You can refer to the the ms docs and can create the function using following options.While using
func init
command in cloud shell, Java is not available in the list to select.I believe, you selected node. I chose custom, as Java is not there in the list then I got below error.
Here, I am using Maven commands to create Java function. You can also use visual studio code as given in ms docs.
Used below command to create function in Maven.
mvn archetype:generate "-DarchetypeGroupId=com.microsoft.azure" "-DarchetypeArtifactId=azure-functions-archetype" "-DjavaVersion=8"
mvn clean install
before executing the function locally.mvn azure-functions:run
.mvn azure-functions:deploy
.You can choose your preferred development tool to create an azure function in Java.