Skip to content

Commit 67adca5

Browse files
committed
Java updates
1 parent 15c1bd2 commit 67adca5

File tree

1 file changed

+87
-3
lines changed

1 file changed

+87
-3
lines changed

articles/azure-functions/how-to-create-function-azure-cli.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,101 @@ To enable the Functions host to connect to the default storage account using sha
213213

214214
At this point, the Functions host is able to connect to the storage account securely using managed identities instead of shared secrets. You can now deploy your project code to the Azure resources.
215215

216+
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python"
216217
[!INCLUDE [functions-publish-project-cli](../../includes/functions-publish-project-cli.md)]
218+
::: zone-end
219+
::: zone pivot="programming-language-java"
220+
## Update the pom.xml file
221+
222+
After you've successfully created your function app in Azure, you must update the pom.xml file. In this way, Maven can deploy to your new app instead of trying to create new Azure resources.
223+
224+
1. In Azure Cloud Shell, use this [`az functionapp show`](/cli/azure/functionapp#az-functionapp-show) command to get the deployment container URL and ID of the new user-assigned managed identity:
225+
226+
```azurecli
227+
az functionapp show --name <APP_NAME> --resource-group AzureFunctionsQuickstart-rg \
228+
--query "{userAssignedIdentityResourceId: properties.functionAppConfig.deployment.storage.authentication.userAssignedIdentityResourceId, \
229+
containerUrl: properties.functionAppConfig.deployment.storage.value}"
230+
```
231+
232+
In this example, replace `<APP_NAME>` with the names of your function app.
233+
234+
1. In the project root directory, open the pom.xml file in a text editor, locate the `properties` element and make updates to these specific values:
235+
236+
| Property name | Value |
237+
| ---- | ---- |
238+
|`java.version` | Use the same [supported language stack version](supported-languages.md) you verified locally, such as `17`. |
239+
|`azure.functions.maven.plugin.version`| `1.37.1` |
240+
|`azure.functions.java.library.version`| `3.1.0` |
241+
|`functionAppName`| The name of your function app in Azure. |
242+
243+
1. Find the `configuration` section of the `azure-functions-maven-plugin` and replace it with this XML fragment:
244+
245+
```xml
246+
<configuration>
247+
<appName>${functionAppName}</appName>
248+
<resourceGroup>AzureFunctionsQuickstart-rg</resourceGroup>
249+
<pricingTier>Flex Consumption</pricingTier>
250+
<region>....</region>
251+
<runtime>
252+
<os>linux</os>
253+
<javaVersion>${java.version}</javaVersion>
254+
</runtime>
255+
<deploymentStorageAccount>...</deploymentStorageAccount>
256+
<deploymentStorageResourceGroup>AzureFunctionsQuickstart-rg</deploymentStorageResourceGroup>
257+
<deploymentStorageContainer>...</deploymentStorageContainer>
258+
<storageAuthenticationMethod>UserAssignedIdentity</storageAuthenticationMethod>
259+
<userAssignedIdentityResourceId>...</userAssignedIdentityResourceId>
260+
<appSettings>
261+
<property>
262+
<name>FUNCTIONS_EXTENSION_VERSION</name>
263+
<value>~4</value>
264+
</property>
265+
</appSettings>
266+
</configuration>
267+
```
268+
269+
1. In the new `configuration` element, make these specific replacements of the elipses (`...`) values:
270+
271+
| Configuration | Value |
272+
| ---- | ---- |
273+
|`region` | The region code of your existing function app, such as `eastus`. |
274+
|`deploymentStorageAccount`| The name of your storage account. |
275+
|`deploymentStorageContainer`| The name of the deployment share, which comes after the `\` in the `containerUrl` value you just obtained. |
276+
|`userAssignedIdentityResourceId`| The fully-qualified ID of your managed identity, which you just obtained. |
277+
278+
1. Save your changes to the _pom.xml_ file.
279+
280+
You can now use Maven to deploy your code project to your existing app.
281+
282+
## Deploy the function project to Azure
283+
284+
1. From the command prompt, run this command:
285+
286+
```console
287+
mvn clean package azure-functions:deploy
288+
```
217289

218290
## Invoke the function on Azure
219291

220292
Because your function uses an HTTP trigger and supports GET requests, you invoke it by making an HTTP request to its URL. It's easiest to do this in a browser.
221293

222-
Copy the complete **Invoke URL** shown in the output of the publish command into a browser address bar. When you navigate to this URL, the browser should display similar output as when you ran the function locally.
294+
1. Use this [`az functionapp function show`](/cli/azure/functionapp/function#az-functionapp-function-show) to get the URL for the `HttpExample` function endpoint:
295+
296+
```azurecli
297+
az functionapp function show --name <APP_NAME> --resource-group "AzureFunctionsQuickstart-rg" \
298+
--function-name HttpExample --query invokeUrlTemplate -o tsv
299+
```
300+
301+
In this example, replace `<APP_NAME>` with the names of your function app.
223302

224-
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-java"
225-
[!INCLUDE [functions-streaming-logs-cli-qs](../../includes/functions-streaming-logs-cli-qs.md)]
303+
1. Copy and paste the returned endpoint URL in your browser address bar and run the function.
226304
::: zone-end
305+
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python"
306+
## Invoke the function on Azure
307+
308+
Because your function uses an HTTP trigger and supports GET requests, you invoke it by making an HTTP request to its URL. It's easiest to do this in a browser. Copy the complete **Invoke URL** shown in the output of the publish command into a browser address bar. When you navigate to this URL, the browser should display similar output as when you ran the function locally.
309+
::: zone-end
310+
227311
[!INCLUDE [functions-cleanup-resources-cli](../../includes/functions-cleanup-resources-cli.md)]
228312

229313
## Next steps

0 commit comments

Comments
 (0)