3
votes

I have a PowerShell script which creates an azure function app on a consumption plan and its associated storage account within a resource group using the azure cli following the example In the Microsoft Docs

However to enable application insights I have to go to the azure portal, find the func select monitor and click enable application insights.

How can I expand that script to enable automate this step for the newly created function? I have been unable to find any specific documentation or examples and I would prefer to avoid resource templates if possible.

1
Is this about Azure PowerShell or Azure CLI? The title and text are conflicting. :)twitchax
I'm using the azure cli from a powershell scriptTwisted
No Confusion @JoyWang I'm waiting to see if there is another answer which automates the inisights creationTwisted
AFAIK, azure cli does not support to create app insights directly, please refer to command list, if you want to access it, you could try this way.Joy Wang-MSFT
So no way to automate creation of application insights other than resource templates in json?Twisted

1 Answers

2
votes

OF course, you could enable Application Insights to the azure function by Azure CLI.

But you need to create the Application Insights in the portal first, currently, it is unable to create Application Insights via Azure CLI.

You could follow the steps below.

1.Go to your Application Insights in the portal, copy the Instrumentation Key in the screenshot.

enter image description here

2.After creating the function app by your command , just use the CLI command below.

az functionapp config appsettings set --name <functionname> --resource-group <resourcegroupname> --settings 'APPINSIGHTS_INSTRUMENTATIONKEY = <Instrumentation Key>'

It works fine on my side, you could check it in the portal.

enter image description here

enter image description here