How to use .NET Core 3.x with Azure Function App Powershell Runtime? - azure

I have created a new Function App using the below resource in my template:
{
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/sites",
"name": "[parameters('caAppName')]",
"location": "[parameters('location')]",
"kind": "functionapp",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
],
"identity": {
"type": "SystemAssigned"
},
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[toLower(parameters('caAppName'))]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~3"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "~10"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "powershell"
},
]
}
}
I run the below code in the function app in the portal Write-Host "$([System.Security.Cryptography.X509Certificates.X509Certificate2].Assembly.Location)"
I get D:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.2.8\System.Security.Cryptography.X509Certificates.dll
But if I use the Function App console:
D:\Program Files\dotnet\shared\Microsoft.NETCore.App> ls
2.2.8
2.2.8.installed
3.0.3
3.0.3.installed
3.1.3
3.1.3.installed
So 3.1.3 is present, but the function is not executing with it.
I only even noticed because I tried to use System.Security.Cryptography.PbeParameters and the type is missing (along with some other AsymmetricAlgorithm stuff)
How do I resolve this?

The .NET Core version is determined by the Azure PowerShell worker, which depends on the PowerShell SDK. PowerShell 6 is the only version currently available in Azure Functions, and it depends on .NET Core 2.x, this is why your PowerShell Function is executed in this context. In order to use .NET Core 3.x, you have the following options:
recommended: wait for PowerShell 7 support in Azure Functions (expected to be deployed within the next 2-4 weeks);
spawn a separate executable from your PowerShell function.

Related

ARM template Azure Web App - How do you specify Stack Settings (.NET, .NET Core,...)?

In ARM template for Azure Web App, how do you specify the stack settings for the app (.NET, .NET Core, PHP, ...)? I cannot see any field for it.
Thank you
When you create azure webapp on portal, choose Running stack as .Net Core 3.0(Current).
Then click Review+Create > Download a template for automation. You will see the ARM template which contain metadata attribute and the current stack value is dotnetcore.
{
"apiVersion": "2018-02-01",
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('location')]",
"properties": {
"name": "[parameters('name')]",
"siteConfig": {
"appSettings": [],
"metadata": [
{
"name": "CURRENT_STACK",
"value": "[parameters('currentStack')]"
}
]
},
// redacted some values
}
}
Adding to Joey's answer, the value for CURRENT_STACK for .NET Core would be dotnetcore.
{
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"name": "<name>",
"location": "[resourceGroup().location]",
"kind": "app",
"properties": {
"enabled": true,
"siteConfig": {
"metadata": [
{
"name": "CURRENT_STACK",
"value": "dotnetcore"
}
]
}
}
}
As a small note: This proposed solution does only work for NEW WebApps... if you want to CHANGE an existing WebApp from .Net4.x to .NetCore you also must clear "netFrameworkVersion". Otherwise the stack is not changed.
So correct would be:
{
"apiVersion": "2018-02-01",
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('location')]",
"properties": {
"name": "[parameters('name')]",
"siteConfig": {
"appSettings": [],
"netFrameworkVersion": "",
"metadata": [
{
"name": "CURRENT_STACK",
"value": "dotnetcore"
}
]
},
// redacted some values
}
}

How to Set Up Application Insights from an Release Pipeline/ARM Templates

We have an Azure DevOps release pipeline, which sets up all of our Azure resources in a location. I can create everything successfully with ARM templates, but I'm struggling to link the App Service with the App Insights resource.
If I were doing it manually, I'd click a "Turn on site extension" button in the AppInsights blade of the App Service (under the heading "Enable Application Insights through site extension without redeploying your code").
I've tried adding an "Azure App Service Manage" step to my release pipeline, set to install the "Application Insights extension for Azure App Service" extension:
In addition, I've added an "Azure App Service Manage" step to my release pipeline, set to "Enable Continuous Monitoring":
But the result is still that AppInsights is connected, but the extension is not installed:
Is there any way I can do this automatically? Either via an ARM template, a PowerShell script, or something else?
Edit: In the "Extensions" blade, I can see "Application Insights extension for Azure App Service" (v2.6.5) and "ASP.NET Core Logging Extensions" (v2.2.0), but I'm still asked to "Turn on site extension" in the "Aplication Insights" blade.
In an ARM-template you can do:
{
"type": "Microsoft.Web/sites",
"apiVersion": "2018-02-01",
"name": "[variables('web_app_service_name')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('plan_name'))]",
"[resourceId('Microsoft.Insights/components', variables('app_insights_name'))]"
],
"kind": "app",
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(variables('app_insights_name'), '2015-05-01').InstrumentationKey]"
},
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"value": "~2"
}
]
}
}
}
Refer to documentation at https://learn.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps#automate-monitoring
i think you would need to do something like that:
{
"apiVersion": "2015-08-01",
"name": "[parameters('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
"displayName": "Website"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"[resourceId('microsoft.insights/components/', parameters('appInsightsName'))]"
],
"properties": {
"name": "[parameters('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]",
"Microsoft.ApplicationInsights.AzureWebSites"
],
"properties": {
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(concat('microsoft.insights/components/', parameters('appInsightsName'))).InstrumentationKey]"
}
},
{
// this bit installs application insights extension
"apiVersion": "2015-08-01",
"name": "Microsoft.ApplicationInsights.AzureWebSites",
"type": "siteextensions",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
],
"properties": {
}
}
]
}
I've never actually tried this, but looks correct, link to the example I've found: https://github.com/tomasr/webapp-appinsights/blob/master/WebSite.json
Make sure that your app settings key is APPINSIGHTS_INSTRUMENTATIONKEY and not ApplicationInsights:InstrumentationKey. Somewhere in the MS docs it gives the impression that you can use either. In fact that's not the case, in Azure you need to use the former otherwise Application Insights won't be enabled for server side insights.
In order for the Azure Portal to show an active integration with Application Insights, you need to set three app settings.
https://learn.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps?tabs=net#automate-the-creation-of-an-application-insights-resource-and-link-to-your-newly-created-app-service
{
"resources": [
{
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference('microsoft.insights/components/AppMonitoredSite', '2015-05-01').InstrumentationKey]"
},
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"value": "[reference('microsoft.insights/components/AppMonitoredSite', '2015-05-01').ConnectionString]"
},
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"value": "~2"
}
]
},
"name": "[parameters('name')]",
"serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"hostingEnvironment": "[parameters('hostingEnvironment')]"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"microsoft.insights/components/AppMonitoredSite"
],
"apiVersion": "2016-03-01",
"location": "[parameters('location')]"
},
{
"apiVersion": "2016-09-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[parameters('location')]",
"properties": {
"name": "[parameters('hostingPlanName')]",
"workerSizeId": "[parameters('workerSize')]",
"numberOfWorkers": "1",
"hostingEnvironment": "[parameters('hostingEnvironment')]"
},
"sku": {
"Tier": "[parameters('sku')]",
"Name": "[parameters('skuCode')]"
}
},
{
"apiVersion": "2015-05-01",
"name": "AppMonitoredSite",
"type": "microsoft.insights/components",
"location": "West US 2",
"properties": {
"ApplicationId": "[parameters('name')]",
"Request_Source": "IbizaWebAppExtensionCreate"
}
}
],
"parameters": {
"name": {
"type": "string"
},
"hostingPlanName": {
"type": "string"
},
"hostingEnvironment": {
"type": "string"
},
"location": {
"type": "string"
},
"sku": {
"type": "string"
},
"skuCode": {
"type": "string"
},
"workerSize": {
"type": "string"
},
"serverFarmResourceGroup": {
"type": "string"
},
"subscriptionId": {
"type": "string"
}
},
"$schema": "https://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0"
}
See also my other answer on this: Azure Cli How to enable Application Insights for webapp

Azure - Set WebSocket On from ARM json template

I'm trying to turn WebSockets On for an Azure WebApp from an Azure ARM json template that deploys my whole infrastructure.
Here is an extract with regards to the Azure Web App. It doesn't work, i.e the WebSockets are still Off. I unsuccessfully tried different spelling: webSocketsEnabled or WebSockets.
"resources":[
{
"name": "[variables('MyApp')]",
"type": "Microsoft.Web/sites",
"location": "Brazil South",
"apiVersion": "2016-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('MyAppPlanBrazil'))]"
],
"tags": {
"[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('MyAppPlanBrazil')))]": "Resource",
"displayName": "MyAppAppBrazil"
},
"properties": {
"name": "[variables('MyAppPlanBrazil')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('MyAppPlanBrazil'))]",
"siteConfig": {
"AlwaysOn": true,
"webSocketsEnabled": true,
"connectionStrings": [
{
...
},
{
...
},
]
}
}
]
UPDATE
As suggested in answer below I updated the apiVersion to "2016-08-01" but this still doesn't work.
Also note that while my schema is the one described here, apiVersion is squiggled in VS and it says the authorized value is "2015-08-01" only.
UPDATE2
I tried the solutions below. They work for their authors but not for me. I guess the problem is elsewhere. My infrastructure is already deployed and I try to update it with webSocketsEnabled. Whereas in the solution below I imagine the authors directly create the web app with webSocketsEnabled.
Also, I coupled webSocketsEnabled with alwaysOn whereas the pricing tier of my webapp doesn't allow "AlwaysOn" (as it says in the portal I need to upgrade to use that feature) so I'll try without alwaysOn.
UPDATE3
At the end, the above template worked when I removed AlwaysOn.
Thank you to those who tried to help me.
Set your api version to this: "2016-08-01"
Use
"webSocketsEnabled": true
This is from the Microsoft.Web/sites template reference:
https://learn.microsoft.com/en-us/azure/templates/microsoft.web/sites
The api version you are using (2015-08-01) from:
https://github.com/Azure/azure-resource-manager-schemas/blob/master/schemas/2015-08-01/Microsoft.Web.json
Doesn't have web sockets in it, but the later one:
https://github.com/Azure/azure-resource-manager-schemas/blob/master/schemas/2016-08-01/Microsoft.Web.json
Does have webSocketsEnabled.
Please have a try to use the following code. It works correctly on my side.
Updated: add whole test arm template and you could have a try to use the following code with your service plan name and resource group name
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverFarmName": {
"type": "string",
"defaultValue": "YourPlan"
},
"serverFarmResourceGroup": {
"type": "string",
"defaultValue": "ResourceGroupName"
}},
"variables": {
"ARMtemplateTestName": "[concat('ARMtemplateTest', uniqueString(resourceGroup().id))]"},
"resources": [
{
"name": "[variables('ARMtemplateTestName')]",
"type": "Microsoft.Web/sites",
"location": "southcentralus",
"apiVersion": "2015-08-01",
"dependsOn": [ ],
"tags": {
"[concat('hidden-related:', resourceId(parameters('serverFarmResourceGroup'), 'Microsoft.Web/serverFarms', parameters('serverFarmName')))]": "Resource",
"displayName": "ARMtemplateTest"
},
"properties": {
"name": "[variables('ARMtemplateTestName')]",
"serverFarmId": "[resourceId(parameters('serverFarmResourceGroup'), 'Microsoft.Web/serverFarms', parameters('serverFarmName'))]"
},
"resources": [
{
"name": "web",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('ARMtemplateTestName'))]"
],
"tags": {
"displayName": "enableWebSocket"
},
"properties": {
"webSocketsEnabled": true,
"alwaysOn": true
}
},
{
"apiVersion": "2015-08-01",
"name": "connectionstrings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('ARMtemplateTestName'))]"
],
"properties": {
"ConnString1": {
"value": "My custom connection string",
"type": "custom"
},
"ConnString2": {
"value": "My SQL connection string",
"type": "SQLAzure"
}
}
},
{
"name": "appsettings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('ARMtemplateTestName'))]"
],
"tags": {
"displayName": "Appsetting"
},
"properties": {
"key1": "value1",
"key2": "value2"
}
}
]
}],
"outputs": {}
}
Test Result:
All the above solution should work.
My initial snippet worked as well ... as soon as I removed alwaysOn.
Indeed, I was using a free tiers App Service Plan for which alwaysOn is not available. While there was no errors or anything else indicating something wrong, I could not set webSocketEnabled and alwaysOn at the same time in that case.

Azure BizTalk Transform Service API ARM Template Creation

I have created below ARM template for creating "BizTalk Transform Service "(API APP) which is using in Logic Apps.
{
"type": "Microsoft.Web/sites",
"apiVersion": "2015-08-01",
"name": "[parameters('apiapps_customertransformation_name')]",
"location": "[resourceGroup().location]",
"kind": "apiApp",
"tags": {
"packageId": "TransformService"
},
"properties": {
"name": "[parameters('apiapps_customertransformation_name')]",
"gatewaySiteName": "[parameters('gatewayName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('svcPlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "EMA_MicroserviceId",
"value": "[parameters('apiapps_customertransformation_name')]"
},
{
"name": "EMA_Secret",
"value": "[parameters('gatewayToAPIappSecret')]"
},
{
"name": "EMA_RuntimeUrl",
"value": "[concat('https://', parameters('gatewayName'), '.azurewebsites.net')]"
},
{
"name": "WEBSITE_START_SCM_ON_SITE_CREATION",
"value": "1"
}
]
}
}
},
{
"type": "Microsoft.AppService/apiapps",
"apiVersion": "2015-03-01-preview",
"name": "[parameters('apiapps_customertransformation_name')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "APIApp"
},
"properties": {
"package": {
"id": "TransformService"
},
"updatePolicy": "Auto",
"accessLevel": "PublicAnonymous",
"host": {
"resourceName": "[parameters('apiapps_customertransformation_name')]",
"resourceType": "Microsoft.Web/sites"
},
"gateway": {
"resourceName": "[parameters('gatewayName')]",
"resourceType": "Microsoft.AppService/gateways"
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('apiapps_customertransformation_name'))]"
]
}
I am able to successfully created the API in Azure Portal, but when I try to add the Map component in Transform API. It says not found.
Can you please let me know how to enable map component?
Or is there any way to directly create a Map component while deploying ARM Template?
Seem that you are trying to use the preview_V1 transform, i would suggest not to use that as it will be deprecated soon.
Try the preview_V2 "Xml Transform" function in LogicApp itself.
Checkout this documentation to get startedXml Transform in LogicApps
LogicApp Documentation https://azure.microsoft.com/en-us/documentation/articles/app-service-logic-what-are-logic-apps/

Deploy a node.js site using Azure Resource Manager

I'm struggling with a ARM deployment script for my node.js application. If I point to a repo with an MVC application it all works fine, but not using an node.js app.
Are there any specific settings for node.js sites?
Here is the resource part of my script:
{
"apiVersion": "2015-08-01",
"name": "[parameters('nodeName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('nodeName'))]": "Resource",
"displayName": "Website"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('nodeName'))]"
],
"resources": [
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "sourcecontrols",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', concat(parameters('nodeName')))]"
],
"properties": {
"repoUrl": "https://github.com/microServiceBus/microservicebus.node.git",
"branch": "master",
"IsManualIntegration": true
}
}
],
"properties": {
"name": "[parameters('nodeName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('nodeName'))]",
"siteConfig": {
"appSettings": [
{
"Name": "hubUri",
"Value": "[parameters('hubUri')]"
},
{
"Name": "nodeName",
"Value": "[parameters('nodeName')]"
},
{
"Name": "organizationaId",
"Value": "[parameters('organizationaId')]"
}
]
}
}
}
The issue was that the name of the repo had a dot in it (microservicebus.node.git). I believe the bug is fixed or is going to be fixed soon.

Resources