bashazure-cli

Azure CLI Bash - attaching an app insights resource to api managment


I can create an api management instance

    az apim create \
        --name "$apimName" \
        --resource-group "$resourceGroupName" \
        --publisher-name 'Publisher' \
        --publisher-email 'Myemail@email.com.au' \
        --tags "${resourceTags[@]}"

and I can create an app insights instance

    az monitor app-insights component create \
        --app "${apimName}-appins" \
        --location "australiaeast" \
        --resource-group "$resourceGroupName" \
        --tags "${resourceTags[@]}"

How do I attach the api insights to api management?


Solution

  • Try the command below, replace the values with yours.

    az resource create --resource-type 'Microsoft.ApiManagement/service/loggers' -g '<apim-group-name>' -n '<apim-name>/loggers/<appinsight-name>' --properties '{
        "loggerType":"applicationInsights",
        "description": null,
        "credentials": {
          "instrumentationKey": "<Instrumentation-Key-of-your-appinsight>"
        },
        "isBuffered": true,
        "resourceId": "/subscriptions/<subscription-id>/resourceGroups/<appinsight-group-name>/providers/microsoft.insights/components/<appinsight-name>"
    }'
    

    enter image description here

    enter image description here